点击A页面按钮如何 改变 B页面textview 中的内容

2025-04-04 00:09:21
推荐回答(1个)
回答1:

JAVA---
public void onCreate(Bundle b){
super.onCreate(b);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.button);
final EditText edit = (EditText)findViewById(R.id.edit);
final TextView text = (TextView)findViewById(R.id.text);
button.setOnClickListener(new OnClickListener(){
@Override //监听点击事件
public void onClick(View v) {
text.setText(edit.getText().toString());
}
});
}
XML--

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
android:id="@+id/edit"
android:inputType="text"
android:layout_width="200dip"
android:layout_height="50dip"
android:layout_alignParentTop="true">