View1を拡張するクラスがありますView。R.layout.test2.xmlこのクラスで膨らませたいView1。このクラスに次のコードを入れました
public class View1 extends View {
View view;
String[] countries = new String[] {"India", "USA", "Canada"};
public View1( Context context) {
super(context);
LayoutInflater mInflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view=mInflater.inflate(R.layout.test2, null, false);
}
}
別のクラスからHome、この膨張したビューがいくつかの状況でそこにあるようにしたい 、Homeクラスで次のコードを書きました:
public class Home extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
CreateView();
}
public void CreateView() {
LinearLayout lv=(LinearLayout)findViewById(R.id.linearlayout);
View1 view = new View1(Home.this);
lv.addView(view);
}
}
しかし、プロジェクトを実行しても、アクティビティには何も表示されません。