フォームのように動作するカスタムの編集テキストがあります。ラベル、編集テキスト、ボタンがあります。私はレイアウトにそれを含めるために、フォームを繰り返し使用できるようにタグを使用しています。ボタンにしたい機能は、クリックするとフォームを再現することです。これは、最初のフォームの最初のクリックで可能です。しかし、私が新しいフォームのボタンをクリックすると、何の処置もありません。しかし、最初のフォームボタンをクリックすると、新しいフォームが作成されます。これは私のXMLです:私はそれを含みます。一般的にonClickListenerをinflated xmlボタンに設定しました
<?xml version="1.0" encoding="utf-8"?>
<TextView android:id="@+id/form_textview"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:textSize="14sp" android:text="Number:" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:id="@+id/form_edittext"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageButton android:id="@+id/form_button"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:src="@drawable/ic_menu_example" android:paddingLeft="1dp"
android:paddingRight="1dp" />
</LinearLayout>
そして、これは私が動的に新しいフォームを追加しようとしている方法です:
public final void onClick(final View view)
{
if (view == findViewById(R.id.form_button))
{
try{
LinearLayout layout = (LinearLayout) findViewById(R.id.contacteditll);
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View tempView = vi.inflate(R.layout.form, null);
numberEntryViews.add(tempView);
layout.addView(tempView);
ImageButton btn = (ImageButton) tempView.findViewById(R.id.form_button);
btn.setOnClickListener(this);
}
catch (Exception e)
{
e.printStackTrace();
Log.d(TAG, "Failed to inflate");
}
}
}
私はこれを実装する際のさまざまな方法を試してみましたが、私は持っています運がない。どんな助けや提案も大変感謝しています。