Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a listview into a fragment?
    primarykey
    data
    text
    <p>I am a beginner in android development. For a project, I would like to know how to implement a listview into a fragment ?</p> <p>In my project, I have 3 fragments.</p> <p>I have to retrieve all the contacts which are in my phone. (I am using this example => <a href="http://samir-mangroliya.blogspot.fr/p/android-read-contact-and-display-in.html" rel="nofollow">http://samir-mangroliya.blogspot.fr/p/android-read-contact-and-display-in.html</a>). Then, I'll put them into one af the fragment, which contains a listview.</p> <p>I am searching for many example, but it is only listview into ACTIVITY example.</p> <p>Can you please help me ?</p> <p>Best regards,</p> <p>Tofuw</p> <p>PS : Sorry for my bad english, I'm french :/</p> <p><strong>EDIT</strong></p> <p>Here is my code :</p> <pre><code>public class PhoneFrag extends ListFragment { private List&lt;Contact&gt;listecontact=new ArrayList&lt;Contact&gt;(); 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&lt;String&gt;adapter=new ArrayAdapter&lt;String&gt;(getActivity(), android.R.layout.simple_expandable_list_item_2, listecontact); setListAdapter(adapter); } </code></pre> <p>I have an error at the third last line :</p> <blockquote> <p>the constructor ArrayAdapter(FragmentActivity, int, List) is undefined</p> </blockquote> <p>Can you help me please ?</p> <p>Tofuw</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload