0

I'm trying to make a ListView in Android where some items have details and some items do not. For those items that have details, I want them to be clickable and for a click on them to present a new fragment. For those items that have no details, I want to hide an ImageView and set the list item to be "unclickable".

I'm trying to accomplish this in the following way (this is in my @Override getView method in my ArrayAdapter class):

ParseGeoPoint location  = itemScan.getParseGeoPoint("location");

ImageView chevron       = (ImageView)convertView.findViewById(R.id.chevron_image_view);

if (location == null) {
    subtitleLabel.setText("{Location Data Unavailable}");
    chevron.setVisibility(View.GONE);
    convertView.setClickable(false);

} else {
    subtitleLabel.setText(""); <-- Not important
    chevron.setVisibility(View.VISIBLE);
    convertView.setClickable(true);

}   

Here's my list view's on item click listener:

mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        // This may be unnecessary when I get this 
        // issue solved, but I put this in because 
        // of the odd behavior described below
        if (view.isClickable() == true) {
            // Push to a new fragment
        }
    }
});

Part of this code works as expected and part does not. The list view items have their labels populated correctly. The list view items have the "disclosure chevron" shown or hidden as expected.

Weirdly, though, the click-ability of the views seems to be inverted from my expectations. The "good" items (the ones with details) don't respond to clicks/taps in any way. The "bad" items (the ones without details) have the audible "click" sound played, but the if statement in my OnItemClickListener() prevents the code from firing. So, my list view is rendered nonfunctional.

Have I misunderstood somehow what is the intended functionality of setClickable(boolean)? I got this idea from this answer.

1 Answer 1

0

Im guessing that your using a ArrayList to store your data you could do this

 mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            ArrayList Object Type itemScan = arrayList.get(position);
            ParseGeoPoint location  = itemScan.getParseGeoPoint("location");

            if (location == null) {
                  return;

           } else {
              // Push to a new fragment
           }   
        }
    });
1
  • Ok. This makes sense, but ideally, I would like to avoid the "click" sound for those items that won't push to a new fragment. Ideas?
    – mbm29414
    Mar 30, 2015 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.