Long click on ListFragment

Yes, the solution posted by tsync works for me. I too had ran into same problem and considered that this is not possible. I tried the above suggestion as follows: public class ProjectsFragment extends ListFragment { @Override public void onActivityCreated(Bundle savedState) { super.onActivityCreated(savedState); getListView().setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, … Read more

How do you implement context menu in a ListActivity on Android?

On the onCreate method call registerForContextMenu like this: registerForContextMenu(getListView()); and then populate the menu on onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo). The menuInfo argument can provide information about which item was long-clicked in this way: AdapterView.AdapterContextMenuInfo info; try { info = (AdapterView.AdapterContextMenuInfo) menuInfo; } catch (ClassCastException e) { Log.e(TAG, “bad menuInfo”, e); return; } long … Read more

creating a menu after a long click event on a list view

First you need to register your context menu on list view. lv = (ListView) findViewById(R.id.list_view); registerForContextMenu(lv); Then, just override activity methods. /** * MENU */ @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); if (v.getId()==R.id.list_view) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu_list, menu); } } @Override public boolean onContextItemSelected(MenuItem item) { … Read more

Detecting a long press in Android

GestureDetector is the best solution. Here is an interesting alternative. In onTouchEvent on every ACTION_DOWN schedule a Runnable to run in 1 second. On every ACTION_UP or ACTION_MOVE, cancel scheduled Runnable. If cancelation happens less than 1s from ACTION_DOWN event, Runnable won’t run. final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)