0

私は現在、最初のスピナーを使用しています。しかし、実装できないため、onItemSelectedListenerの実行中にちょっと行き詰まりました。最初は CommonWares の本の方法に従おうとしましたが、うまくいきましたが、私の方法も今はうまくいきません。

最初は、アクティビティに AdapterView を直接実装させようとしましたが、唯一の結果は、Eclipse がインターフェイス AdapterView を使用できないことを通知し、それを作成するように求めたことでした...しかし、まったく同じエラーが再び発生しました。

public class Lunchplace extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mensa);
    Context c = getApplicationContext();

    Spinner dateSelection = (Spinner)findViewById(R.id.date);

    //ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.)
    // get all the little tidbits of extra informations
    Bundle extras = getIntent().getExtras();

    String location = extras.getString("Mensa");
    // this function will download the Lunchfile - if necessary
    Data lunchData = new XMLData(c);

    // set the header text
    TextView mensaname = (TextView)findViewById(R.id.header);
    mensaname.setText(location);

    // get the spin view out of the xml
    Spinner spin = (Spinner)findViewById(R.id.date);

    // attach it to an adapter
    ArrayAdapter adapter = ArrayAdapter.createFromResource(
            this, R.array.days, android.R.layout.simple_spinner_item);
    // I should be able to put a custom layout of the spinner in there.. I bet
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin.setAdapter(adapter);


    spin.setOnClickListener(
             new  AdapterView.OnItemSelectedListener() {           

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

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub

        }
             }
    );

    // set the current day of the week as the default selection
    spin.setSelection(Tools.getDayOfWeek());

    // get the tablelayout
    TableLayout tl = (TableLayout)findViewById(R.id.MenuTable);
    lunchData.getMenuforDay(c,tl,location);

    TextView counterTV = new TextView(c, null, R.style.MenuField);

    }
}

その問題をどのように解決できるかについて、誰かがアイデアを持っていますか?

4

1 に答える 1

0

OnItemSelectedListener の実装には特別なことはありません。次のように試してみてください:

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if ("YourDayToHandle".equals(spinner.getSelectedItem())) {
                // do smth useful here
            }
        }

    public void onNothingSelected(AdapterView<?> parent) {}
});
于 2010-11-11T18:12:08.207 に答える