Buttons in listview
do not fire onclick
event but if I click the line it does.
I have a listview in a fragment
. Each row in the listview has 2 buttons
and a textview
. Problem is, if I click the textview
the event is fired but if I click the buttons the event is not fired. I only have the string in my data adapter since I am dealing with files and that is the filename. The buttons will be actions on the files.
Here is the adapter(I don't have a class for the data adapter, do I have to?)
public class fileExplorerAdapter extends ArrayAdapter<String> {
private ArrayList<String> items;
public fileExplorerAdapter(Context context, int textViewResourceId, ArrayList<String> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.file_explorer_cell, null);
}
String fileName = items.get(position);
TextView tt = (TextView) v.findViewById(R.id.txtViewFileName);
tt.setText(fileName);
return v;
}
}
here is the setup for the event in the fragment
// ListView Item Click Listener
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Log.d("debug", "in item clicked");
// ListView Clicked item index
int itemPosition = position;
// ListView Clicked item value
String itemValue = (String) listView
.getItemAtPosition(position);
// Show Alert
Toast.makeText(
rootView.getContext(),
"Position :" + itemPosition + " ListItem : "
+ itemValue, Toast.LENGTH_LONG).show();
}
});