ListFragment OnListItemClick not being called
If you have an item in your layout that can steal input from other components like a CheckBox, that component needs to be defined as not focusable.
ListFragment onListItemClick not called, only CustomAdapter does the job
The answer that has worked for me to trigger onListItemClick
and that I have not read anywhere yet has been to set getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE)
on the onActivityCreated
method of the ListFragment
.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mAdapter = new EventListArrayAdapter(this.getActivity(), mEvents);
new EventListArrayAdapter(this.getActivity(), mEvents);
mList.setAdapter(mAdapter);
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
There is not need to use the android:descendantFocusability="blocksDescendants"
in the item xml with this.
ListFragment onListItemClick not called
Change the parent activity to a regular Activity, not a ListActivity.
ListFragment onListItemClick not working
Move your code in onCreateView() method from onActivityCreated() method
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
String[] values = new String[] { "List", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, values);
setListAdapter(adapter);
return super.onCreateView(inflater, container, savedInstanceState);
}
UPDATE:
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
FragmentManager manager = getFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
ft.replace(R.id.pager, new Home());
ft.commit();
}
Implement this method in your Fragment.
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
// Make sure that we are currently visible
if (this.isVisible()) {
// Do your stuff here
if (!isVisibleToUser) {
Log.d("MyFragment", "Not visible");
}
}
}
onListItemClick not called on Listfragment
Ok, I found the error. It was something complete different.
In fact I had a rating bar as a list item and even tough it did not cover the whole list item it somehow got all the click events.
Changing the visibility to GONE for now solved the problem. So the problem was here the layout of a single list item and not the adapter.
ListFragment.onListItemClick() not being called; possibly due to Navigation Drawer
I discovered the issue. I added a FrameLayout
to contain my Fragment
, but I see now that the DrawerLayout
already contains within it a FrameLayout
(called content_frame
). So I just used content_frame
instead of fragment_container
.
ListFragment OnListItemClick Not Calling When Using BaseAdapter
Based on your getView()
method from the adapter, I see that you have a CheckBox
in the list item. You need to add android:focusable="false"
to it (as a matter of fact you need to do it to any control that is focusable by default).
ListFragment and onListItemClick not working
You need to figure out how you should handle your tabs. You're attaching and detaching in your TabListener, but showing and hiding when clicking through your ListView.
You either detach all your current fragments and then attach the new one, or change your tab listeners to .show() and .hide() instead.
EDIT: According to the last comment in this answer, there's a good example of keeping your tab history while switching between tabs.
The following implementation of TabListener is simple but will not keep your back stack intact. When switching to another tab, you're not selecting one to hide. This just glazes over it and detach the whole thing.
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
mFragment = Fragment.instantiate(mActivity, mClass.getName());
ft.replace(android.R.id.content, mFragment, mTag);
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
if (mFragment != null)
ft.detach(mFragment);
}
}
onListItemClick not working in a ListFragment placed in an activity
Don't embed scrollable widgets like ScrollView
(from the row layout) in another scrollable widget like a ListView
.
Related Topics
Android:Passing a Hash Map Between Activities
Disabling Android O Auto-Fill Service for an Application
How to Send File Using Bluetooth on Android Programatically
Copy Database from Assets to Databases Folder
An Android App Remembers Its Data After Uninstall and Reinstall
Android How to Create Runtime Thumbnail
How to Check If Receiver Is Registered in Android
Android Split Action Bar with Action Items on the Top and Bottom
Android: How to Create an "Ongoing" Notification
Android Imageview: Setting Drag and Pinch Zoom Parameters
Switch Keyboard Profile Programmatically
How to Call Methods of a Service from Activity
Importing Module in Android Studio
Firebase Admin Sdk for Android, Methods Not Found
How to Prevent Going Back to the Previous Activity
How to Add Multiple Widgets in the Same App