I am a beginner in android development. For a project, I would like to know how to implement a listview into a fragment ?
In my project, I have 3 fragments.
I have to retrieve all the contacts which are in my phone. (I am using this example => http://samir-mangroliya.blogspot.fr/p/android-read-contact-and-display-in.html). Then, I'll put them into one af the fragment, which contains a listview.
I am searching for many example, but it is only listview into ACTIVITY example.
Can you please help me ?
Best regards,
Tofuw
PS : Sorry for my bad english, I'm french :/
EDIT
Here is my code :
public class PhoneFrag extends ListFragment
{
private List<Contact>listecontact=new ArrayList<Contact>();
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
public void onActivityCreated(Bundle savedInstanceState, Context context)
{
super.onActivityCreated(savedInstanceState);
String[]values=new String[]{};
Cursor phones=context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null,null,null);
while(phones.moveToNext())
{
String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String num=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Contact contact=new Contact();
contact.setName(name);
contact.setNum(num);
listecontact.add(contact);
}
phones.close();
ArrayAdapter<String>adapter=new ArrayAdapter<String>(getActivity(), android.R.layout.simple_expandable_list_item_2, listecontact);
setListAdapter(adapter);
}
I have an error at the third last line :
the constructor ArrayAdapter(FragmentActivity, int, List) is undefined
Can you help me please ?
Tofuw