0
LayoutInflater를 사용하여 두 번째 레이아웃에서 첫 번째 레이아웃으로 가져온 버튼을 이벤트에 제공하고 싶습니다.tableLayout 행의 버튼에 이벤트를 지정 하시겠습니까?
여기 내 코드입니다.
main.xml에
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="ScrollViewSize,TextFields,HardcodedText,UselessLeaf,UselessParent" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/editTextSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ems="10" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<EditText
android:id="@+id/editTextTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
<Button
android:id="@+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
</LinearLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Tagged Searches"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_marginTop="10dp"
android:background="#C90" >
<TableLayout
android:id="@+id/TableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableLayout>
</ScrollView>
<Button
android:id="@+id/buttonClearTask"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Clear Tags" />
</LinearLayout>
</TableLayout>
gonder_edit_button.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="HardcodedText,UselessParent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="@+id/buttonEklenecek"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginRight="30dp"
android:text="Add" />
<Button
android:id="@+id/buttonEdit"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:text="Edit" />
</LinearLayout>
그리고 내 자바 코드.
`super.onCreate (savedInstanceState);
setContentView (R.layout.main);
buttonSave = (Button) findViewById (R.id.buttonSave);
editTextSearch = (EditText) findViewById (R.id.editTextSearch);
editTextTag = (EditText) findViewById (R.id.editTextTag);
TableLayout1 = (TableLayout) findViewById (R.id.TableLayout1);
buttonSave.setOnClickListener (new OnClickListener ()
{
@ Override
public void onClick (View v)
{
layoutInflater = (LayoutInflater) getSystemService (Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate (R.layout.gonder_edit_button , null);
TableLayout1.addView (view);
buttonEklenen = (Button) view.findViewById (R.id.buttonEklenecek);
buttonEklenen.setText (editTextTag.getText ().toString ());
buttonEklenen.setOnClickListener (new OnClickListener ()
{
@ Override
public void onClick (View arg0)
{
String URLstring = "http://search.twitter.com/search?p=" + buttonEklenen.getText ().toString ();
Intent webIntent = new Intent ( Intent.ACTION_VIEW , Uri.parse (URLstring));
startActivity (webIntent);
}
});
}
});`
예를 들어, 검색 및 태그를 7 번 저장하면 이벤트 제 3의 버튼을주고 싶습니다.