2011-10-02 72 views
0

這個班怎麼了?在列表視圖中點擊尚未註冊,我試圖做一個記錄,但它不進入setItemOnClickListenerListView沒有迴應點擊

public class Chosen extends Activity{ 
SimpleCursorAdapter adapter; 
String[] getResult; 
Cursor c; 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.chosen); 
    Intent i=getIntent(); 
    Bundle extras=i.getExtras(); 
    final TextView t=(TextView) findViewById(R.id.tv1); 
    int num=extras.getInt("category"); 
    ArrayList al=new ArrayList<String>(); 
    switch(num) 
    { 
    case 0:c=Splash.db.getSocial(Login.uname);break; 
    case 1:c=Splash.db.getMail(Login.uname);break; 
    case 2:c=Splash.db.getBank(Login.uname);break; 
    case 3:c=Splash.db.getMisc(Login.uname);break; 
    } 
    if(c.moveToFirst()) 
    { 
     do 
     { 
      al.add(c.getString(1)); 
     }while(c.moveToNext()); 
    } 

    getResult=new String[al.size()]; 
    al.toArray(getResult); 
    ListView lv=(ListView) findViewById(R.id.list); 
    lv.setClickable(true); 
    ArrayAdapter ad=new ArrayAdapter(this,R.layout.chosenitemlist,R.id.client,getResult); 
    lv.setAdapter(ad); 

    lv.setTextFilterEnabled(true); 
    lv.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> arg0, View arg1, int position, 
       long id) { 
      // TODO Auto-generated method stub 
      Log.w("akash", "in list item click"); 
      t.setText("clicked"); 
      Toast.makeText(getApplicationContext(), "hello", Toast.LENGTH_LONG).show(); 
     } 
    }); 
} 

}

回答

3

有趣。 首先,嘗試我檢查自己的幾種場景:http://xjaphx.wordpress.com/2011/07/14/listview-doesnt-respond-to-onitemclicklistener/

如果問題仍然存在,您可能想分享您的源代碼,我想分析它是否是新場景。如果你不能'共享全部源代碼,然後嘗試創建一個新的項目,並把所有必要的代碼,並分享:)

+0

非常感謝先生!我忘了提及我的行佈局也有一個按鈕,我把它的android:focusable設置爲false,並且它工作正常! – user962339

0

我發現了另一個場景(未列出xjaphx):我的行佈局有一個textview和兩個圖像,其中一些有「clickable = true」。將其設置爲「false」解決了該問題。