私はアンドロイドを初めて使っていて、基本的な例を修正しようとしています。アンドロイドの現在のビューにコンポーネントを追加する方法
main.xmlは
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<Button android:layout_width="228dp" android:layout_height="wrap_content" android:id="@+id/addButton" android:text="@string/addBtn"></Button>
</LinearLayout>
のようなもので、ボタンのクリックにTextFieldを追加したいです。子を追加する方法
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn=(Button)findViewById(R.id.addButton);
btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
EditText editText = new EditText(v.getContext());
//Append the editText to View
}
どのように現在のビュー/レイアウトに追加しますか?
コンポーネントを追加するには、新しいビューを追加する必要がありますか?表示またはレイアウトするコンポーネントを直接追加しますか? – MalTec
あなたの場合のように、コンポーネントをビューとして扱い、EditTextを直接ビューに追加することができます。 –
レイアウトはビューの親ですか? – MalTec