2011-12-07 51 views
0

這段代碼有什麼問題?我無法將選定的項目查看到第二個視圖?從微調控制器打開新的活動selectedItem

public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2 
, long arg3){ 

int Index = arg0.getSelectedItemPosition(); 

       Toast.makeText(arg0.getContext(), 
         arg0.getItemAtPosition(Index).toString() + " View Selected", Toast.LENGTH_SHORT).show(); 

       Intent newIntent = new Intent(GazaGuideSample.this, GuideCategories.class); 
       newIntent.putExtra("text",arg0.getItemAtPosition(Index).toString()); 
       startActivity(newIntent); 

      } 
+0

您可以發佈logcat的消息,錯誤? – Style

+0

你不能使用arg2作爲索引嗎? – user994886

回答

0

試試這個:

mYourSpinner.setOnItemSelectedListener(new OnItemSelectedListener()  
     { 
      @Override 
      public void onItemSelected(AdapterView<?> parent, View view, 
        int pos, long id) 
      {       
       //int Index = parent.getSelectedItemPosition();pos - is SelectedPosition 

     Toast.makeText(parent.getContext(), 
       pos + " View Selected", Toast.LENGTH_SHORT).show(); 

     Intent newIntent = new Intent(GazaGuideSample.this, GuideCategories.class); 
     newIntent.putExtra("text",pos.toString()); 
     startActivity(newIntent); 
      } 

      @Override 
      public void onNothingSelected(AdapterView<?> arg0) 
      {   
      }   
     }); 
+0

什麼都沒發生!!!!!!! public class GuideCategories extends Activity { protected void onCreat(Bundle savedInstanceState){ \t super.onCreate(savedInstanceState); \t setContentView(R.layout.guidecategories); \t \t TextView tv =(TextView)findViewById(R.id.textView1); \t tv.setText(getIntent()。getExtras()。getString(「Your Selected Item is:」+「text」)); \t } } – mmattar

+0

您是否在AndroidManifest中註冊了您的GuideCategories? – Style