My code involves showing data retrieved from a parse backend using a parsequeryadapter. Based on the text retrieved, my code displays some images in the listview which are basically buttons with custom backgrounds and some text.
The problem is that the onListItemClick method does not seem to be called at all. (It might work if it is called)
Construct of code is like so: NavActivity contains a fragment which contains a child listfragment defined in the XML.
This is the getItemView method in my ParseQueryAdapter
@Override
public View getItemView(ParseObject object, View v, ViewGroup parent) {
if (v == null) {
v = View.inflate(context, R.layout.post_item, null);
}
super.getItemView(object, v, parent);
//find the elements here and set the value from the ParseObject returned
TextView1 = (TextView) v.findViewById(R.id.NumberTxtView);
Holder = (LinearLayout) v.findViewById(R.id.feloniesList);
if (object != null) {
Holder.removeAllViewsInLayout();
TextView1.setText(object.getString("comment"));
JSONArray jsonArray = object.getJSONArray("incident");
for (int i = 0; i < jsonArray.length(); i++) {
//Create a new button
Button button = new Button(getContext());
String btnText = null;
int resId = 0;
try {
//Get the string from the JSON Array
String item = jsonArray.getString(i);
button.setFocusable(false);
button.setText(item);
} catch (JSONException e) {
e.printStackTrace();
}
Holder.addView(button, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
}
return v;
}
ListItemClick method
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
feedObject = feedAdapter.getItem(position);
mListener.onListItemClicked(feedObject.getObjectId());
}
I read here that making other components as non focusable, will solve the problem, but it is not helping. Any help would be appreciated
I found the answer, it seems focusable is not only true for buttons / checkboxes, but also elements like HorizontalScrollViewer. I had my linearlayout in which I was adding the buttons, enclosed in a horizontalscrollviewer. After I removed said element, click functions are working fine.