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>
我的Java代碼。
`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);
}
});
}
});`
例如,當我保存搜索和標記七次時,我想給一個事件第三個按鈕。