例如其他布局里有两个Button,
id分别为button1和button2
在两个Button控件里加上
android:onClick="onClick";
然后在MainActivity里写:
LayoutInflater inflater = LayoutInflater.from(this);
View mView = inflater.inflate(R.layout.其他布局.xml,null);
Button button = (Button) mView.setOnClickListener(this);//implements View.OnClickListener
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
//如果你要改写button2的text的话:
Button button = (Button)findViewById(R.id.button2);
button.setText(" 要改的话 ");
//如果你要改的是button1的text的话:
Button button = (Button)findViewById(R.id.button1);
button.setText(" 要改的话 ");
或者:
Button button = (Button)v;
button.setText("要改的话");
break;
case R.id.button2:
//类推
break;