0

からアイテムを選択した後、別のコンテンツを表示するにはどうすればよいSpinnerですか? Spinnerチェーン店の店舗を作りたい。

4

1 に答える 1

0

スピナーが常に一番上にあるようにしたい。スピナーの下のコンテンツに変わる唯一のもの

Spinnerアクティビティで簡​​単なメソッドを作成して、 (変更されないままになります)の下のレイアウトを更新します。そのメソッドは、OnItemSelectedListener上のセットから呼び出されSpinnerます。次のようになります。

private void changeAdress(int newSelectedAdress) {
    // The ImageView and the TextView will be already in the layout
    ImageView map = (ImageView) findViewById(R.id.theIdOfTheImage);
    // Set the image. You know the current address selected by the user
    // (the newSelectedAddress int) so get it from the array/list/database
    // where you stored it
    // also set the image
}

コールバックから上記のメソッドをonItemSelected呼び出します。

yourSpinnerRefference.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
                          changeAddress(position);              
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

これがあなたが望むものでない場合は、説明してください。

編集: データを保持する 2 つの配列を作成します。

int[] images = {R.drawable.imag1, R.drawable.imag2 ..etc...};
//also for the text
String[] text = {"text1", "text2 ...etc...};

次に、上記で推奨した方法でこれら 2 つの配列を使用します。

private void changeAdress(int newSelectedAddress) {
     ((ImageView)findViewById(R.id.mapView1)).setImageResource(images[newSelectedAddress]); 
     // assing an id to the TextView in your layout and do the same as above.
}

ImageView複数のandは必要ありませんTextViews

于 2013-02-09T16:11:22.943 に答える