我的代码看起来像这样:
case 2:
final TextView scoretext = new TextView (this);
return new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("How cold or hot do you feel today?")
.setView(qolscorelayout)
.setPositiveButton("Confirm",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton)
{
SeekBar qolDialogSeekbar = (SeekBar)qolscorelayout.findViewById(R.id.qolscore_seekbar);
todayScore = qolDialogSeekbar.getProgress();
showDialog(3);
}
}
).create();
qolscorelayout在前面定义为:
qolscorelayout = inflater.inflate(R.layout.qolscore_dialog, (ViewGroup)findViewById(R.id.qolscore_dialog_root_element)); //Layout for getting Seekbar in Dialog
我想在对话框中找到一个TextView,就在滑块上方。
我正在考虑做类似的事情:
case 2:
final TextView scoretext = new TextView (this); //NEW
return new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("How cold or hot do you feel today?")
.setView(qolscorelayout)
.setPositiveButton("Confirm",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton)
{
SeekBar qolDialogSeekbar = (SeekBar)qolscorelayout.findViewById(R.id.qolscore_seekbar);
todayScore = qolDialogSeekbar.getProgress();
scoretext.setText("" + todayScore); //NEW
showDialog(3);
}
}
).create();
但是如何让它将TextView放在对话框中呢?
答案 0 :(得分:1)
只是添加已经说过的内容。
将textview放在qolscore_layout中。然后你可以像这样修改它的内容:
qolscorelayout = inflater.inflate(R.layout.qolscore_dialog, (ViewGroup)findViewById(R.id.qolscore_dialog_root_element));
final TextView scoretext = (TextView) qolscorelayout.findViewById(R.id.scoretext);
scoretext.setText("" + todayScore); //NEW