2
如何爲EditText控件在其inputType爲數字時以編程方式設置文本?當inputType爲數字時,如何爲EditText控件設置文本
<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 WorkedHoursET insteaD OF WorkingHoursET –
是的,你是對的:)非常感謝 – Glolita