2012-04-17 55 views
0

我想知道是否有人知道如何開始一個新的活動,當你改變一個微調的價值,而不必按下按鈕。
我一直在網上搜索幾個小時,但我找不到任何讓我走向正確方向的東西。所以我希望這裏有人能幫助我。開始一個新的活動與微調

這只是我的一個標準的微調代碼:

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); 
+0

壞UI設計。沒有人期望紡紗工開展一項活動。控件意味着擺弄。當你點擊一個複選框觸發頁面導航時,你不喜歡它在網頁上嗎? – 2012-04-17 15:26:47

+0

它的順序由微調所以它加載連接的API與一個不同的變量 – 2012-04-17 15:29:35

回答

0

設置setOnItemSelectedListener ,,,,如果選擇一些onItemSelected叫,否則onNothingSelected被稱爲

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 

      } 
     }); 
+0

所以我的微調說最新和評級和意見,所以我應該把那些? – 2012-04-17 15:38:08

+0

相同的一個按鈕,設置setonitemSelected .... – 2012-04-17 15:39:05

+0

嗯。 ques im too noob for android development – 2012-04-17 15:48:04