将光标定位在AlertDialog中

时间:2014-04-12 16:06:07

标签: android alertdialog

我想将光标放在我在setView中显示的值后面的AlertDialog中。因此,当值为" 2.40"时,光标应该在0之后正确定位。有没有办法实现这个目标?

final EditText input = new EditText(co);
TextView tx= (TextView) findViewById(R.id.price_accrued);//3.0.7
input.setText( (String) tx.getText());
new AlertDialog.Builder(co)
.setTitle("whatever")
.setMessage("Total amount including tip")
.setView(input)
 aso....

1 个答案:

答案 0 :(得分:0)

怎么样

final EditText input = new EditText(co);
TextView tx= (TextView) findViewById(R.id.price_accrued);
input.setText( (String) tx.getText());
int position = input.length();
Selection.setSelection(input, position);

input.setSelection(position);

也使用tx.getText().toString()代替(String) tx.getText()) ......它更好,更清晰......