Search code examples
androidandroid-listviewonclickonclicklistenerlistitem

onListItemClick doesn't work


So, my onListItemClick is not working for some reason. I use the same code structure in another activity and that one is working perfectly. And when I try to implement the same method here, it just doesn't work at all. The Toast doesn't work. And the intent to detailactivity also doesn't work. I'm sure my naming and labeling is fine. The list items doesn't even feel like they are clickable. Can someone help me out here, please?

public class MainActivity extends ListActivity {

    String objectId;
    protected List<ParseObject> mInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_info);

    //**** There is a bunch of code here that takes import the list view from an adapter. I believe they are working fine. ***//
    }

    //**** this part below is not working. This is the section where if you click on the list item, it brings you to the detailactivity.
    @Override
    protected void onListItemClick(ListView l,View v, int position, long id){
        super.onListItemClick(l, v, position, id);

        ParseObject infoObject = mInfo.get(position);
        String objectId = infoObject.getObjectId();

        Toast.makeText(getApplicationContext(),objectId, Toast.LENGTH_SHORT).show();

        Intent Details = new Intent(MainActivity.this, DetailsActivity.class);
        Details.putExtra("objectId", objectId);
        startActivity(Details);
    }

Solution

  • I found an answer to solve this by adding android:focusable="false" inside of the the views in the listview/customlayout that will be imported to the activity. I got the answer from this link: onListItemClick is not working for listview?