Adding Onlistitemlick/onitemlongclick In A Listfragment
SOLVED IN A COMMENT: Adding onListItemLick/onItemLongClick in a ListFragment The problem was generated from an ImageButton in the layout of the single element in the ListFragment t
Solution 1:
Edited Answer: Maybe the components of the layout were stealing the input from other components of the layout
Solution 2:
I have got two solution
Simply Override onListItemClick
@Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id);
Log.i("position",position);
}
On the root layout. Add this code
android:descendantFocusability="blocksDescendants"
Hope it helps
Solution 3:
Add the super constructor and override it:
@OverridepublicvoidonListItemClick(ListView l, View v, int pos, long id) {
super.onListItemClick(l, v, pos, id);
Log.d("CLICK", "pressed");
}
EDIT: try this code
publicclassFragmentDextendsListFragment {
private SQLiteDatabase db;
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Viewv= inflater.inflate(YOUR LISTFRAGMENT LAYOUT HERE, container, false);
myDatabasemyDBHelper=newmyDatabase(getActivity());
db = myDBHelper.getWritableDatabase();
Log.d("DB", "Insert fatto");
String[] res_columns = newString[] {myDatabase.COLUMN2, myDatabase.COLUMN2,};
StringsortOrder= myDatabase.COLUMN1 + " DESC";
Stringwhere="*";
CursortestCursor= db.rawQuery("select * from " + database.DATABASE_TABLE, null);
myAdapteradapter=newmyAdapter(getActivity(),
R.layout.list_element,
testCursor,
res_columns,
newint[] { },
0);
setListAdapter(adapter);
return v;
}
@OverridepublicvoidonListItemClick(ListView l, View v, int pos, long id) {
super.onListItemClick(l, v, pos, id);
Log.d("CLICK", "pressed");
}
Post a Comment for "Adding Onlistitemlick/onitemlongclick In A Listfragment"