activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button1" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView1" /> <include layout="@layout/include_layout1" /> </LinearLayout> include_layout1.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="100dp" android:orientation="vertical" > <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button2" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView2" /> </LinearLayout> MainActivity.java public class MainActivity extends FinalActivity { @ViewInject(id = R.id.textView1) TextView textView1; @ViewInject(id = R.id.textView2) TextView textView2; @ViewInject(id = R.id.button1, click = "fun1") Button button1; @ViewInject(id = R.id.button2, click = "fun2") Button button2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView1.setText("tv1"); textView2.setText("tv2"); } public void fun1(View v) { textView1.setText("tv11"); } public void fun2(View v) {//这里必须要是public,并且参数要写View v,不然没有反应 textView2.setText("tv22"); } } // public void show(){ //没反应 // Toast.makeText(MainActivity.this, "单击按钮", Toast.LENGTH_SHORT).show(); // } // public void show(View v){//有反应,正确 // Toast.makeText(MainActivity.this, "单击按钮", Toast.LENGTH_SHORT).show(); // } public void show(View v,String str){//没反应 str = "good"; Toast.makeText(MainActivity.this, "单击按钮"+str, Toast.LENGTH_SHORT).show(); }
