Make List Clickable
I've already tried using clickable and focusable but nothing seems to allow list items to be clickable. xml file
Solution 1:
Android sometimes shows a weird behavior when you are trying to setOnItemClickListner on Listview item while you have set onClickListner on the sub-items of Listview row. Try to check you "Adapter" class and make sure everything is fine and well managed according to the standards. Use ViewHolder to access the sub-items in Adapter class. Here is the sample class of Adapter. Use this one, hope it'll work.
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import de.hdodenhof.circleimageview.CircleImageView;
/**
* Created by Zohaib Hassan on 11/28/2016.
*/publicclassInboxAdapterextendsArrayAdapter<InboxRow> {
ArrayList<InboxRow> items;
Context context;
publicInboxAdapter(Context context, int resource, ArrayList<InboxRow> items) {
super(context , resource , items);
this.context = context;
this.items = items;
}
@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this positionInboxRowrowItem= getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
ViewHolder viewHolder; // view lookup cache stored in tagif (convertView == null) {
viewHolder = newViewHolder();
LayoutInflaterinflater= LayoutInflater.from(context);
convertView = inflater.inflate(R.layout.inbox_row, null);
viewHolder.tvUserName = (TextView) convertView.findViewById(R.id.tv_user_name_inbox);
viewHolder.tvMessage = (TextView) convertView.findViewById(R.id.tv_message_inbox);
viewHolder.tvTimeCount = (TextView) convertView.findViewById(R.id.tv_time_count_inbox);
viewHolder.userProfilePic = (CircleImageView) convertView.findViewById(R.id.inbox_profile_image);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
/*CircleImageView ivProfileImage Set Background with Picasso*/return convertView;
}
privatestaticclassViewHolder {
TextView tvUserName , tvMessage , tvTimeCount;
CircleImageView userProfilePic;
}
}
One last thing, please make sure the the "ListView" in your layout class is set to "match-parent" for both height and width.
Post a Comment for "Make List Clickable"