【发布时间】:2016-06-22 17:32:26
【问题描述】:
SetHint 仅在 OnClickListener 之后(单击按钮后)更新 TextEdit 在我的情况下,当用户在 TextEdit 中键入一些文本并激活切换时,提示只会在他/她提交按钮被按下后更改。例如,如果我按下 Toggle,提示将与原始提示相同。
我想让 SetHint 在打开或关闭切换设置后立即工作。想要在我按下切换后将 TextEdit 中的提示更改为“自定义文本”。否则我希望 TextEdit 保留原始提示文本。不确定是否需要更改它,因为我在布局中使用相同的提示文本。
public class MainActivity extends Activity {
private Button button;
private TextEdit text;
private ToggleButton toggle;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
text = (TextEdit) findViewById(R.id.myid);
toggle = (ToggleButton) findViewById(R.id.myid2);
if (toggle.isChecked()) {
text.setHint("Custom Text");
} else {
text.setHint("Text");
}
button.setOnClickListener(new View.OnClickListener() {
...
【问题讨论】:
标签: android