我想通过按Button
来更改TextView
,但不知道如何正确执行。如何通过按下按钮来更改TextView的文本
这是我的布局的一部分:
<TextView android:id="@+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change text!" />
这是我的活动:
public class Click extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
// ???
}
});
}
}
我应该把里面onClick()
方法?
一个重要的t hing:只有当您离开onClick块时才更新该字段,但无法两次更新相同的字段。 – onizukaek