【发布时间】:2018-10-11 00:48:41
【问题描述】:
我有一个按钮和 1 个编辑文本。按钮设置为“更改”,EditText 为 enable-false。当您单击一个按钮时,其文本将更改为“保存”,并且可以输入编辑文本。第二次按下后,文本再次变为“更改”,按钮变为 Enable-false。
如何实现?
【问题讨论】:
标签: android button android-edittext
我有一个按钮和 1 个编辑文本。按钮设置为“更改”,EditText 为 enable-false。当您单击一个按钮时,其文本将更改为“保存”,并且可以输入编辑文本。第二次按下后,文本再次变为“更改”,按钮变为 Enable-false。
如何实现?
【问题讨论】:
标签: android button android-edittext
在你的按钮上使用这个 onClickListener -
Button yourButton = (Button) view.findViewById(R.id.button)
EditText yourEditText = (EditText) view.findViewById(R.id.edittext)
yourButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!yourEdittext.isEnabled()){
yourButton.setText("Save");
yourEditText.setEnabled(true);
counter++;
}else if (yourEdittext.isEnabled()){
yourButton.setText("Change again");
yourButton.setEnabled(false);
}
}
});
确保为起始点设置初始按钮的文本和禁用编辑文本
【讨论】: