-1

こんにちは、1 つのアプリを開発する必要があります。ここで、mysql データベースのスピナー値を更新する必要があります。

例: 状態....ここでは、最初にアプリを実行する必要があり、常に Q のみを表示します..ここでは、アプリを実行する必要がある後にステータス Q を C に更新する必要があります。これは、ステータス C を自動的に表示することを意味します。これを開発できますか?なぜ常に表示される Q...ここでコードを管理するにはどうすればよいですか? ここでは、以下のコードを使用しました。

 private void createSpinnerDropDown() {

    //get reference to the spinner from the XML layout
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);

    //Array list of animals to display in the spinner
    List<String> list = new ArrayList<String>();

    list.add("Q");
    list.add("P");
    list.add("F");
    list.add("I");
    list.add("C");

    //create an ArrayAdaptar from the String Array
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
    //set the view for the Drop down list
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //set the ArrayAdapter to the spinner
    spinner.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    //attach the listener to the spinner
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

}

どうすればこれを開発できますか。

4

2 に答える 2

0
if(list.contains(DATABASE.FETCH()))
   spinner.setSelection(list.indexOf(DATABASE.FETCH()));

DATABASE.FETCH()は、データベースからデータ(C)をフェッチするためのメソッドです。

于 2012-09-06T10:20:12.603 に答える
0

選択した項目を保存する代わりに、selectedItemPosition のみを取得します。

int selectedIndex = spinner.getSelectedItemPosition();

データベースからスピナーアイテムを設定したい場合は、インデックスをフェッチするだけです。

int SavedIndex = FetchSavedSpinnerIndex();

スピナーのアイテムを次のように設定します

spinner.setSelection(SavedIndex);
于 2012-09-06T10:33:54.827 に答える