【发布时间】:2013-09-20 16:19:00
【问题描述】:
当 EditText 控件的 inputType 为数字时,如何以编程方式为其设置文本?
<EditText
android:id="@+id/WorkingHoursET"
android:layout_width="fill_parent"
android:textColor="@color/white"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/WorkingHoursTV"
android:layout_below="@+id/WorkingHoursTV"
android:layout_marginTop="14dp"
android:ems="10"
android:inputType="number" />
EditText workedHours = (EditText)findViewById(R.id.WorkedHoursET);
workedHours.setText(8); //this is not working
workedHours.setText("8"); //neither this
【问题讨论】:
-
我猜这是因为您传递了错误的 ID WorkedHoursSET 而不是 WorkingHoursSET
-
是的,你是对的 :) 非常感谢
标签: android android-edittext settext