2012-05-13 72 views
0

我已經看過其他帖子,我有自定義適配器在我的應用程序工作,但這不會出於某種原因。ListView使用自定義適配器setOnItemClickListener不起作用

我在自定義適配器3個TextViews,他們都設置爲:

android:focusable="false" 
android:focusableInTouchMode="false" 

final ListView VideoList =(ListView)findViewById(R.id.lvVideoList);  
VideoList.setItemsCanFocus(false); 

VideoList.setOnItemClickListener(new OnItemClickListener()  
{    
    @Override 
    public void onItemClick(AdapterView<?> parent, View v,int position, long id) 
    { 
     vibrator.vibrate(intVib); 
     Log.i("test","VideoList onclick called"); 

     Object listItem = VideoList.getItemAtPosition(position); 
     String xList = listItem.toString().replaceAll("\\s+", "").replaceAll("\\n+", ""); 
     if(xList.toString().length() > 1) 
     { 
      String tvUrl = listItem.toString(); 
      Toast toastUDComplete = Toast.makeText(getApplicationContext(), tvUrl.toString(), Toast.LENGTH_SHORT);toastUDComplete.setGravity(Gravity.TOP | Gravity.CENTER, 0, 0); toastUDComplete.show(); 
      //getVideo(v, tvUrl); 
     } 
     else 
     { 
      Toast toastUDComplete = Toast.makeText(getApplicationContext(), "No Videos Available", Toast.LENGTH_SHORT);toastUDComplete.setGravity(Gravity.TOP | Gravity.CENTER, 0, 0); toastUDComplete.show();  
     }     
    }  
}); 
+1

究竟是什麼問題? – Luksprog

+0

當我點擊一個列表項目時,什麼也沒有發生,至少它應該振動 –

+0

請參見[this](http://stackoverflow.com/questions/12328804/listview-setonitemclicklistener-not-working-for-custom-listview-but當我在getItem方法中返回值時,解決了我的問題 –

回答

0

如果在您的適配器佈局,此屬性設置爲它的複選框。

android:focusable="false" 
android:focusableInTouchMode="false" 
相關問題