Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your add method you're setting the arrays to new values <code>listComments = comments;</code> That's replacing your old data with the new data.</p> <p>You could use <a href="http://developer.android.com/reference/java/lang/System.html#arraycopy%28java.lang.Object,%20int,%20java.lang.Object,%20int,%20int%29" rel="nofollow">System.arrayCopy()</a> to resize your listArrays to the new size and append the new items. A much less tedious approach, however, would be to store your arrays as <code>List&lt;String&gt;</code>, allowing you to add more items without worrying about resizing lists.</p> <p>The result would look something like this...</p> <pre><code>public class CommentsAdapter extends BaseAdapter { private LayoutInflater inflater; private List&lt;String&gt; comments; private List&lt;String&gt; numbers; private List&lt;String&gt; usernames; public CommentsAdapter(Context context) { inflater = LayoutInflater.from(context); comments = new ArrayList&lt;String&gt;(); numbers = new ArrayList&lt;String&gt;(); usernames = new ArrayList&lt;String&gt;(); } public void add(String[] comments, String[] numbers, String[] usernames) { this.comments.addAll(Arrays.asList(comments)); this.numbers.addAll(Arrays.asList(numbers)); this.usernames.addAll(Arrays.asList(usernames)); notifyDataSetChanged(); } @Override public int getCount() { if (comments == null) return 0; return comments.size(); } @Override public String getItem(int position) { return comments.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.list_item, parent, false); convertView.setTag(new ViewHolder(convertView)); } ViewHolder holder = (ViewHolder) convertView.getTag(); holder.commentView.setText(comments.get(position)); //Other view bind logic here... return convertView; } private static class ViewHolder { public TextView commentView; public TextView numbersView; public TextView usernamesView; public Button usernameButton; public Button numberButton; public ViewHolder(View v) { commentView = (TextView) v.findViewById(R.id.listComment); numbersView = (TextView) v.findViewById(R.id.listNumber); usernamesView = (TextView) v.findViewById(R.id.listPostedBy); usernameButton = (Button) v.findViewById(R.id.listUsernameButton); numberButton = (Button) v.findViewById(R.id.listNumberButton); } } } </code></pre> <p>I also highly recommend reading this page on the Android Developer's site: <a href="http://developer.android.com/training/improving-layouts/smooth-scrolling.html" rel="nofollow">http://developer.android.com/training/improving-layouts/smooth-scrolling.html</a></p> <p>Your current adapter implementation is very inefficient, and that page should help you iron out some kinks.</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.
    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