0

私は、初期化時にspinner.setSelection(0)のデータベースからデータを読み込む私のアクティビティのスピナーを持っています。スピンナーの値を変更すると、spinner.setSelection(1)とすると、データを読み込む前に表示するか(空の場合)、空白/空白のままにしておきます。Spinner onItemSelected EditTextテキストをクリアする

ここに私のコードのスニペットがあります。スピナーリスナー

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(); 
} 

ためonItemSelected

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 
    } 

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> 

内にあるこれはとは何かですフォーカスチェンジ電子など

答えて

0

他には何も行いません明確等しくない見つけた場合

  1. は、それらを比較し、現在のスピナーデータとのEditTextデータを取得し、このロジックを試してみてください
関連する問題