1

我想知道是否有人知道如何开始一项新活动,当您更改微调器的值而无需按下按钮时。
我已经在网上搜索了几个小时,但我找不到任何可以引导我朝着正确方向前进的东西。所以我希望这里有人可以帮助我。

这只是我的标准微调器代码:

protected void onCreate(Bundle savedInstanceState) {

    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.share);

    Button view = (Button) findViewById(R.id.button1);
    view.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent("net.thinkbin.TUTORIAL1"));
            overridePendingTransition(0, 0);
            finish();
        }
    });

    Button menu = (Button) findViewById(R.id.buttonhome);
    menu.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub

            // custom dialog
            final Dialog dialog = new Dialog(context);
            dialog.setContentView(R.layout.custom);

            // set the custom dialog components - text, image and button
            TextView text = (TextView) dialog.findViewById(R.id.text);
            text.setText("Loading...");
            ImageView image = (ImageView) dialog.findViewById(R.id.image);
            image.setImageResource(R.drawable.hourglass);

            dialog.show();
            Thread th = new Thread(new Runnable() {
                public void run() {

                    startActivity(new Intent("net.thinkbin.MENU"));
                    overridePendingTransition(0, 0);
                    dialog.dismiss();
                    finish();

                }
            });
            th.start();
        }
    });

    ArrayAdapter<CharSequence> adapter = ArrayAdapter
            .createFromResource(this, R.array.spinnerfood,
                    android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    Spinner s = (Spinner) findViewById(R.id.spinner1);
    s.setAdapter(adapter);
4

1 回答 1

1

Set setOnItemSelectedListener,,,, if select somethingonItemSelected被调用,elseonNothingSelected被调用

 s.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                 String str = (String) arg0.getSelectedItem();

                             //here print selected value...
                 System.out.println("String is :: " + str);

                             //And StartActivity here...

                    Intent intent = new Intent(YourActivity.this,SecondActivity.class);
                    startActivity(intent);

            }

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

            }
        });
于 2012-04-17T15:26:30.443 回答