TestActivity缺少布局文件加上setContentView(R.layout.自定义的布局);就没事了。

解决方案 »

  1.   

    打开的只有窗口,需要添加布局类,创建方法也如TextView
      

  2.   

    不对,不对,我看错了……你的程序没什么问题啊,在我这里能正确执行。
    能看到testactivity,白底蓝字
      

  3.   

    如果要动态添加,需要指定所属的linearlayout,        LinearLayout layoutParent = new LinearLayout(getContext());
            LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(                
    LinearLayout.LayoutParams.FILL_PARENT,
    LinearLayout.LayoutParams.WRAP_CONTENT);
            TextView textView = new TextView(this);
            textView.setText("Show TestActivity");
            textView.setTextSize(20.0f);
            textView.setTextColor(0xff0000ff);
            textView.setBackgroundColor(0xffffffff);
            layoutParent.addView(textView);
            setContentView(textView);就可以了
      

  4.   

    楼上paramsl应该在LinearLayout之前创建,然后创建LinearLayout时添加paramsl,其他如楼上所言。
      

  5.   

    setContentView(textView);
    改成setContentView(layoutParent);
      

  6.   


    谢谢,你能把你的工程打包发给我吗?我对比下[email protected]
      

  7.   


    谢谢你,呵呵,知道问题了
    昨天敲代码时间已经很晚了,眼一花,手一颤,在TestActivity中的onCreate()方法多加了个字母d导致错误。呵呵,谢谢