Question

I ve tried to solve the problem myself but I can't, I looked for answer similar questions as well but I couldn't find an answer. I have an activity which extends ActivityFragment, then inside that Activity I have a fragment. This fragment has a ListView with a OnItemClickListener. I'm trying to start an activity when an item in the ListView is clicked but nothing is happening, I really don't know what is the problem, it's not crashing just nothing is happening. I tried to do this with a button using an OnClickListener and it worked no problem. Any help would be appreciated.

Java code:

/**
 * Instantiate a layout XML file into its corresponding view object.
 * @return view
 */
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

    ViewGroup view = (ViewGroup) inflater.inflate(R.layout.fragment_favourites_profiles, container, false);

    email = getActivity().getIntent().getStringExtra("Email");

    //Call loadProfiles method
    loadProfiles();

    // Gets ListView
    lv = (ListView) view.findViewById(android.R.id.list);

    // Listener that acts when profile is selected
    lv.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View v,
                        int position, long id) {


                    Intent in = new Intent(getActivity(), ProfileView.class);

                    //Starts activity 
                    startActivity(in);
                }
            });

    return view;  


}

XML ListView:

    <ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" 
    android:divider="@color/color_black"
    android:dividerHeight="1dp">

</ListView>

Thanks for any help

Was it helpful?

Solution

Are you using a ListFragment? If that is the case, instead of adding this OnItemClickListener, override the method onListItemClick from the fragment..it works better for this goal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top