我在向主活动添加自定义类时遇到问题。
我的自定义类中的代码:
public class DetailView extends View {
public DetailView(Context context) {
super(context);
this.setBackgroundColor(0xFF00FF00 );
}
}
主要活动中的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linearLayout = (LinearLayout) findViewById(R.id.linearLayout1);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
linearLayout.setOrientation(LinearLayout.VERTICAL);
txt = new TextView(this);
txt.setText("hello");
txt.setId(6);
txt.setLayoutParams(params);
linearLayout.addView(txt);
DetailView detailView = new DetailView(this.getApplicationContext());
linearLayout.addView(detailView);
}
为什么看不到detailView?我是 android 开发的新手,所以我需要任何我能得到的帮助,或者一些好的链接或任何东西。谢谢