0

i have fragment in project i want create Listview but i cant : how change this code?

public class Menu extends Fragment implements OnClickListener {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.menu, container, false);

    //Button ButtonF1= (Button) rootView.findViewById(R.id.buttonF1);
    //ButtonF1.setOnClickListener(this);

    return rootView;
};

}

and my Xml file :

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    </LinearLayout>
</ScrollView>
sajjad Yosefi
  • 190
  • 2
  • 12

1 Answers1

0

You can see an examples here

Resume:

Instead:

public class Menu extends Fragment

You can use:

public class MyMenu extends ListFragment

It change the methods

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ArrayList<ListviewContactItem> yourListHere = GetYourList();
    setAdapter(new YourListviewAdapter(getActivity(), listContact));
}

onActivityCreated is void and you didn't need to return a view like in onCreateView

Also is necessary to use an adapter (own or standard). You can see about adapters in the previous link.

Is in the adapter where you add the route of your Xml.

VictorPurMar
  • 151
  • 9