Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>-- Update, after looking more into documentation I think you still could use ArrayAdapter --</p> <p>So if you look at the documentation for <a href="http://developer.android.com/resources/tutorials/views/hello-listview.html" rel="nofollow noreferrer">listview</a> you see</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;string-array name="countries_array"&gt; &lt;item&gt;Bahrain&lt;/item&gt; &lt;item&gt;Bangladesh&lt;/item&gt; &lt;item&gt;Barbados&lt;/item&gt; &lt;item&gt;Belarus&lt;/item&gt; &lt;item&gt;Belgium&lt;/item&gt; &lt;item&gt;Belize&lt;/item&gt; &lt;item&gt;Benin&lt;/item&gt; &lt;/string-array&gt; &lt;/resources&gt; </code></pre> <p>and to load those you use:</p> <pre><code>setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, countries)); </code></pre> <p>The problem here is you have to deal with figuring out when they get to the end of the list and how to load more data without blocking the UI.</p> <p>Thus, to save yourself a lot of headache, I recommend using <a href="https://github.com/commonsguy/cwac-endless" rel="nofollow noreferrer">Commonsware Endless Adapter</a> Do so like this:</p> <pre><code>import android.app.ListActivity; import android.os.Bundle; import android.os.SystemClock; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import com.commonsware.cwac.endless.EndlessAdapter; import java.util.ArrayList; public class YourListActivity extends ListActivity { @Override public void onCreate(Bundle state) { super.onCreate(state); setContentView(R.layout.main); String[] countries = getResources().getStringArray(R.array.countries_array); setListAdapter(new YourAdapter(countries)); } class YourAdapter extends EndlessAdapter { public YourAdapter(String[] list) { super(new ArrayAdapter&lt;String&gt;(YourAdapter.this, R.layout.row, android.R.id.text1, list)); } @Override protected View getPendingView(ViewGroup parent) { View row=getLayoutInflater().inflate(R.layout.row, null); return row.findViewById(android.R.id.text1); } @Override protected boolean cacheInBackground() { SystemClock.sleep(10000); // pretend to do work //put logic here to fetch the data //this happens in the background so you can't do anything with the UI //return whether or not you have more data, true if you do false otherwise. boolean haveMoreData = true;//this up to you to figure out return haveMoreData; } @Override protected void appendCachedData() { //here is where you do the work to actually add the data obtained in cacheInBackground to the ArrayAdapter ArrayAdapter&lt;String&gt; a=(ArrayAdapter&lt;String&gt;)getWrappedAdapter(); for (int i=0;i&lt;25;i++) { a.add(a.getCount()); } } } } } </code></pre> <p>here is another question that looks similar to your own on here: <a href="https://stackoverflow.com/questions/1080811/android-endless-list">Android Endless List</a></p> <p>-- Update: How to add multiple string arrays to an adapter -- There are multiple ways to do this, the most simple way would probably be to use the adapters add method..</p> <p>Look at this: <a href="http://developer.android.com/reference/android/widget/ArrayAdapter.html" rel="nofollow noreferrer">http://developer.android.com/reference/android/widget/ArrayAdapter.html</a> and see the method add. Currently you have a variable named adapter:</p> <pre><code>ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, get_msgList); </code></pre> <p>Whenever you want to add more data to that adapter just call:</p> <pre><code> adapter.add("Some new data"); </code></pre> <p>So if you had another String[] array of data and you wanted to add all of it to the current adapter, just use:</p> <pre><code> String[] someNewData = getStringArray();//no idea how you are getting the array, this is just an example for (String s : someNewData) { adapter.add(s); } </code></pre> <p>After you've added the new data you may need to call adapter.notifyDataSetChanged but I'm not sure (it may happen for you).. I would try it first without it and see if everything works as expected and if not add it.</p> <p>Now one thing you will probably want to do is either make the adapter variable an instance variable of your class so you can use it anywhere in the class.</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