フォームのように機能するカスタム edittext があります。ラベル、編集テキスト、およびボタンがあります。フォームを繰り返し使用できるように、タグを使用してレイアウトに含めています。ボタンに持たせたい機能は、クリックしたときの形を再現することです。これは、最初のフォームの最初のクリックで可能です。ただし、新しいフォームのボタンをクリックしてもアクションはありません。ただし、最初のフォーム ボタンをクリックすると、新しいフォームが作成されます。これは私の 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");
}
}
}
これを実装するためにさまざまな方法を試しましたが、うまくいきません。ヘルプや提案は大歓迎です。