我的一个Activity上有一个微调器,初始化时会从spinner.setSelection(0)
的数据库加载数据。当我更改微调器值时,让我们说spinner.setSelection(1)
,我想在加载数据之前清除EdittText ed1
视图中的文本(如果存在)或将其留空/空/空
以下是我的代码片段。
public class TestActivity extends Activity implements
AdapterView.OnItemSelectedListener {
...
Spinner spinner;
EditText ed1;
...
protected void onCreate(Bundle savedInstanceState) {
...
...
spinner = (Spinner) findViewById(R.id.spinner1);
ed1 = (EditText)findViewById(R.id.ed1);
...
adapter = new ArrayAdapter<String>(this,R.layout.temp_layout01,R.id.temptxt01,xNames);
spinner.setAdapter(adapter);
spinner.setSelection(getSpinnerIndex(spinner,mname));
spinner.setOnItemSelectedListener(this);
}
清除EditText数据的方法
private void clearAllFields() {
Log.i(TAG, "Clearing Fields");
ed1.getText().clear(); //test that didn't clear the data
ed1.setText(null); // test that didn't clear the data
}
onItemSelected for spinner listener
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
clearAllFields();
mname = parent.getItemAtPosition(position).toString();
mID = dbHelper.getCurrentData(mname);
spinner.setSelection(getSpinnerIndex(spinner,mname));
populateData();
}
ed1在TableRow
中<TableRow
android:id="@+id/tbHole18TR"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:layout_width="50dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/ed1"
android:background="@color/Green3"
android:textAlignment="center" />
</TableRow>
这与focusChange等有关吗
答案 0 :(得分:0)
试试这个逻辑