2011-11-29 45 views
-2

我已創建微調。當選擇一個項目時,我想顯示一個烤麪包,它會顯示選擇的內容。我怎樣才能做到這一點?選擇微調項目時顯示烤麪包

+3

試着自己先找到一個解決方案。花5分鐘谷歌搜索,你會得到你的答案。嘗試「安卓微調選擇」 – Marmoy

回答

1

http://developer.android.com/reference/android/widget/Toast.html提供了有關Android的Toast功能的所有知識。

+0

其實我可以在開始時獲得吐司消息。但是我希望每次在列表中選擇一個時都會顯示它。 – androiddeveloper

+0

然後每次打電話時都要在該面包上調用.show()。 –

+0

感謝大家從[鏈接](http://developer.android.com/resources/samples/Spinner/src/com/android/example/spinner/SpinnerActivity.html)獲得它。從下次開始,我們會在發佈之前做深入的研究。感謝大家。它應該是 – androiddeveloper

3

試試看看這個代碼。這對我來說很好:

Spinner spinnerone = (Spinner) findViewById(R.id.spinner); 
    ArrayAdapter<String> adapterone = new ArrayAdapter<String> (this,android.R.layout.simple_spinner_item,mtype2); 
    spinnerone.setAdapter(adapterone); 
    spinnerone.setSelection(0); 
    spinnerone.setOnItemSelectedListener(new OnItemSelectedListener() 
    { 
     public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) 
     { 
      int item = spinnerone.getSelectedItemPosition(); 
      y = mtype2[item]; 
      Toast.makeText(getApplicationContext(), y, Toast.LENGTH_SHORT).show(); 
     } 
     public void onNothingSelected(AdapterView<?> arg0) { 
     } 
    }); 
+0

,y應該是一個字符串。但是不要以爲這裏是一個字符串。另外,不能得到這個mtype2.Can你可以澄清?我是Android的初學者,所以不太瞭解。 – androiddeveloper

+0

在這裏mtype2是一個包含項目的字符串數組&y是一個字符串 – Praveenkumar

+0

即使我嘗試過它。但它顯示運行時錯誤。 – androiddeveloper