简体   繁体   中英

ListView With custom Adapter setOnItemClickListener not working

I have looked at the other posts and I have custom adapters working in my app but this will not work for some reason.

I have 3 TextViews in the custom adapter and they are all set to:

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();      
        }                   
    }      
}); 

If there is a checkbox in your adapter layout, set this property to it.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM