Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd listview item to the top of a Android Pull to refresh ListView
    primarykey
    data
    text
    <p>I am using the RefreshableListView (Pull to refresh) from <a href="https://github.com/woozzu/RefreshableListView" rel="nofollow">here</a> .But I am using a Custom ListAdapter and not the ArrayAdapter. It working all fine but the only issue is that it is adding new items to the bottom of the list while <strong>I want new items to be displayed on top.</strong> . I have referred to a lot of articles on the net addressing similar issues but have not found a solution for my issue. It will be great if anybody could point out where I am going wrong. </p> <p>Here are the code snippets:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { final CustomAdapter adapter = new CustomAdapter(this, R.layout.mylist, mItems); mListView = (RefreshableListView) findViewById(R.id.listview); mListView.setAdapter(adapter); // Callback to refresh the list mListView.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(RefreshableListView listView) { ivFooter.setImageResource(R.drawable.back); new NewDataTask().execute(); } }); } </code></pre> <p>and the AsyncTask</p> <pre><code>private class NewDataTask extends AsyncTask&lt;Void, Void, String&gt; { @Override protected String doInBackground(Void... params) { try { Thread.sleep(1000); } catch (InterruptedException e) { } String retVal = myArrayList.get(i); if (i &lt; myArrayList.size() - 1) { i++; } else { i = 0; } return retVal; } @Override protected void onPostExecute(String result) { mItems.add(0, result); mListView.completeRefreshing(); super.onPostExecute(result); } } </code></pre> <p>and Custom Adapter class</p> <pre><code>class CustomAdapter extends BaseAdapter { public int getCount() { return mItems.size(); } public Object getItem(int position) { return mItems.get(position); } public long getItemId(int position) { return position; } public boolean areAllItemsEnabled() { return false; } public boolean isEnabled(int position) { return false; } public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; if (v == null) { LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = vi.inflate(R.layout.mylist, null); } String quote = myArrayList.get(position); if (quote != null) { TextView tt = (TextView) v.findViewById(R.id.tvQuote); ImageView iv = (ImageView) v.findViewById(R.id.ivPicture); if (tt != null) { tt.setText(quote); } if (iv != null) { //Setting image } return v; } </code></pre> <p>'mItems' is the original list with one item and I am adding 'myArrayList' to it. Like I said its working fine but adding elements (on refresh) one by one at the bottom ..while I want the new elements to be added on top. Any inputs would be of great help. </p> <p>Thanks in advance. </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.
    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