2011-06-24 67 views
1

打開對話框中,我發現一個問題,同時對listView..the代碼點擊打開的對話框中,我有回報如下,請檢查是否有任何的錯誤..如何從列表視圖

public void onCreate(Bundle savedInstanceState) { 


     super.onCreate(savedInstanceState); 
     setContentView(R.layout.my_info); 
     ListView lv2; 
     String lv_arr1[]={"Language:NotSpecified"}; 
     lv2=(ListView)findViewById(R.id.listViewInfo1); 
     lv2.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr1)); 

     ListView lvInfo1; 
     ListViewInfo adapter; 
     String lvTitle[]={"online"}; 
     String lvDesc[]={"Change Status"}; 
     adapter = new ListViewInfo(this, lvTitle,lvDesc); 
     lvInfo1=(ListView)findViewById(R.id.listViewInfo2); 
     lvInfo1.setAdapter(adapter); 
     lvInfo1.setOnItemClickListener(this); 

    } 

public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) 
{ 

     final CharSequence[] items = {"Online", "Away", "Do not distrub","Invisible","Offline"}; 

     AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setTitle("Change Status"); 
     builder.setItems(items, new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int item) { 
       Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show(); 
      } 
     }); 

} 
+1

的末尾添加以下代碼,什麼是PR oblem?代碼看起來不錯。 –

+0

onclick沒有對話框出現..so可以plese找到問題在哪裏 – AndroidDev

回答

1

onItemClick方法

AlertDialog alert = builder.create(); 
alert.show(); 
+0

你現在工作..thans – AndroidDev

+0

你現在的工作謝謝.. – AndroidDev

2

builder.show()在對話框初始化結束丟失 - 因此不顯示對話框