Reputation: 6246
I've setup a context menu to appear on short press what I click on an item in a ListView
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
menu.setHeaderTitle("Pick an action");
theView = v;
TextView desc = (TextView) theView.findViewById(R.id.class_description);
String description = (String) desc.getText();
TextView id = (TextView) v.findViewById(R.id.class_id);
Integer ID = Integer.valueOf(String.valueOf(id.getText()));
menu.add(1, ID, 0, getString(R.string.add_to_calender));
menu.add(2, ID, 0, getString(R.string.subscribe_alterations));
assert description != null;
if (!description.equals("")) {
menu.add(3, ID, 0, getString(R.string.view_description));
}
menu.add(4, ID, 0, getString(R.string.view_alterations));
}
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getSherlockActivity(), "Clicked", Toast.LENGTH_SHORT).show();
registerForContextMenu(view);
view.setLongClickable(false);
getSherlockActivity().openContextMenu(view);
}
});
In my listview adapter I've got this line what toggles the visibility of a button
holder.alter.setVisibility(View.VISIBLE);
if ((position % 2) == 0) {
holder.alter.setVisibility(View.INVISIBLE);
}
Here's the button
<Button
android:layout_width="20dp"
android:layout_height="wrap_content"
android:background="@drawable/alterations_btn"
android:textColor="@color/white"
android:layout_alignParentLeft="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold"
android:layout_marginRight="@dimen/padding_small"
android:id="@+id/is_alt"
android:layout_centerInParent="true"
android:text="@string/exclamation_point"/>
When the button is invisible the context menu works, but when it's visible it doesn't.
Can anyone see why?
Upvotes: 0
Views: 55
Reputation: 1873
The first thing you should keep in mind is, whenever there are Clickable elements like Buttons or links in your ListView element, they take the control of click events. And so your ListView will not get the chance to accept the click event.
What you can do is, set the focusable attribute to false for the Button you have in your ListView and see if that helps.
Upvotes: 1