Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What do you mean a "list in android"? It's giving you a list that you can use already.</p> <p>To understand what the <code>&lt;Status&gt;</code> part means, you need to understand <a href="http://download.oracle.com/javase/tutorial/java/generics/index.html" rel="nofollow">generics</a>.</p> <p>Generics allow you to have methods that take and return the type you need, rather than dealing with possible exceptions or accidentally putting the wrong type into a list.</p> <p>Without generics, <a href="http://developer.android.com/reference/java/util/List.html" rel="nofollow">List</a>'s methods (it's an <a href="http://download.oracle.com/javase/tutorial/java/IandI/createinterface.html" rel="nofollow">interface</a> that things such as ArrayList or LinkedList happen to implement) would look like this (only some methods shown):</p> <pre><code>boolean add(Object object); boolean add(int location, Object object); Object get(int location); boolean contains(Object object); </code></pre> <p>Everything is an Object and you could for example, put in anything or get out anything.</p> <p>If you use a generic List, everything is of type Status instead:</p> <pre><code>boolean add(Status object); boolean add(int location, Status object); Status get(int location); boolean contains(Status object); </code></pre> <p>You can then just use your retrieved list and do the following to check if size > 0 and get the first status, as an example (I have no experience with the Facebook API itself so you may have to do something entirely different than this for what you actually need):</p> <pre><code>if (list.size() &gt; 0) { Status myStatus = list.get(0); } </code></pre> <p>You don't have to worry in this case that list.get(index) doesn't return a Status.</p> <p>You can definitely pass this list to anything that says it accepts a List, for example an <a href="http://developer.android.com/reference/android/widget/ArrayAdapter.html" rel="nofollow">ArrayAdapter</a>.</p> <p>Check out <a href="http://download.oracle.com/javase/tutorial/java/generics/index.html" rel="nofollow">generics</a>, <a href="http://download.oracle.com/javase/tutorial/java/IandI/createinterface.html" rel="nofollow">interfaces</a>, and <a href="http://developer.android.com/reference/java/util/List.html" rel="nofollow">Android's java.util.List interface</a> for more info on each of those things!</p> <p><strong>UPDATE</strong></p> <p>To set this list to an ArrayAdapter, <a href="http://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter%28android.content.Context,%20int,%20int,%20java.util.List%3CT%3E%29" rel="nofollow">ArrayAdapter has a constructor just for this</a>:</p> <pre><code>List&lt;Status&gt; status; try { status = rest.getStatus(10); ArrayAdapter&lt;Status&gt; arrayAdapter = new ArrayAdapter&lt;Status&gt;(context, R.layout.list_layout_name, R.id.list_item_textbox, status); listView.setAdapter(arrayAdapter); } catch (EasyFacebookError e1) { // TODO Handle possible errors, of course! e1.printStackTrace(); } </code></pre> <p>Notice ArrayAdapter is also generic. You are going to need to make an XML layout file with a TextView element that has the ID you set in the second resource argument. If you just want what the default layout, you use the two parameters <code>android.R.layout.simple_list_item_1</code>, <code>android.R.id.text1</code>. <code>context</code> is most likely <code>this</code> if you are inside an extended <code>Activity</code> class, or if not, you would pass a reference of the instance of your activity instead.</p> <p>See you just pass the list right into the ArrayAdapter!</p> <p>Note you might want a more complex adapter for more complex views, in which case you would have to subclass an Adapter and override the <code>getView</code> to do whatever with the Status elements. An ArrayAdapter will just put <code>Status.toString()</code> into the specified item text view, which may or may not be what you want.</p>
 

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