Android 文本视图和警报对话框帮助
所以,我有一个列表警报对话框,您可以在其中选择颜色。当用户选择颜色时,我想在文本视图中显示他选择的颜色。该对话框工作正常,但我在文本视图方面遇到问题。我需要一种在运行时更改文本视图文本的方法。有什么建议吗?
这是代码
public void a_Turnus(View view){
setContentView(R.layout.a_turnus);
final TextView text = (TextView)findViewById(R.id.test);
final CharSequence[] items = {"Mat", "Fiz", "Eng"};
final Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Odaberi");
alert.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
text.setText(items[item]);
}
});
text.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog myalert = alert.create();
myalert.show();
}
});
}
So, I have a list alert dialog where i you pick, lets say a color. When the user picks the color i want to display the color he picked in a textview. The dialog is working fine, but I'm having problems with the textview. I need a way to change the text of the textview during runtime. Any suggestions?
Here's the code
public void a_Turnus(View view){
setContentView(R.layout.a_turnus);
final TextView text = (TextView)findViewById(R.id.test);
final CharSequence[] items = {"Mat", "Fiz", "Eng"};
final Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Odaberi");
alert.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
text.setText(items[item]);
}
});
text.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog myalert = alert.create();
myalert.show();
}
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
MyTextView.setText()
,该函数立即更新文本Use
MyTextView.setText()
, this function update the text immediately