Short Background: Basically my group's first android application that we are constructing for a Senior Design class at our University. It was essentially a navigation and user interface practice while implementing a database. The instructor plans to use the application in the future so we had to make it backwards compatible for android 2.3.x
Problem: It would seem SherlockListFragment doesn't implement a onListLongItemClick and it has a mind of its own inside the code. It disallows me to override it and it doesn't contain a super method.
Code:
public class DBList extends SherlockListFragment implements
TextToSpeech.OnInitListener {
Class
private int selectedItem;
variable that is being manipulated
public void onListItemClick(ListView l, View v, int itemPosition, long id)
{
selectedItem = (int) id;
speakOut(this.items.get((int)id).getName());
}//END void onListItemClick
Basic clicks work as intended, the selectedItem is here for code testing. It's intended use is to only speakout the string and nothing else.
@Override
public void onListLongItemClick(ListView l, View v, int itemPosition, long id)
{
super.onListItemLongClick(l, v, itemPosition, id);
Log.v(LOGTAG, "List Long Selection: launching context menu");
Log.v(LOGTAG, "Long id: " + id);
selectedItem = (int) id;
l.showContextMenu();
}//END void onListLongItemClick
This throws error: Method onListLongItemClick is undefined for the type SherlockListFragment
It's intended use is creating the context menu to edit or delete the item in the database. I know the context menu works but for whatever reason none of the code in this section is read. The logtags are never echoed back and the context menu opens even if the code line is removed.
Answer:
Apparently I can't think about using getListView(). Answer thanks to rciovati I guess I got confused when it was launching the context menu regardless of whether it was in the code or not.
public void onActivityCreated(Bundle savedState)
{
super.onActivityCreated(savedState);
Log.v(LOGTAG, "Context Menu registartion complete");
registerForContextMenu(getListView());
getListView().setOnItemLongClickListener(new OnItemLongClickListener()
{
public boolean onItemLongClick(AdapterView<?> l, View v, int itemPosition, long id)
{
Log.v(LOGTAG, "List Long Selection: launching context menu");
selectedItem = (int) id;
l.showContextMenu();
return true;
}
});
}
ListFragment
class doesn't have that method, so it's normal you can't override it.
Anyway you can intercept item long click as explained here