ListView使用自定义适配器setOnItemClickListener无法正常工作

时间:2012-05-13 15:53:48

标签: android android-listview

我查看了其他帖子,并且我的应用程序中有自定义适配器,但由于某种原因这不起作用。

我在自定义适配器中有3个TextView,它们都设置为:

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 个答案:

答案 0 :(得分:0)

如果适配器布局中有复选框,请将此属性设置为它。

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