Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic display the contents of ScrollView in Android
    text
    copied!<p>What I am trying to achieve is that, I am having an <code>ArrayList&lt; String > data = new ArrayList&lt; String >();</code> that contains values form 1 to 100. Now if I want to display this data in a scrollView then I will write the following code:</p> <pre><code>for(int i=0; i&lt;data.size(); i++) { View v = getLayoutInflator.inflate(R.layout.mycontainer, null); TextView tv = (TextView)v.findViewById(R.id.tv1); tv.setText(data.get(i)); layout.addView(v); } </code></pre> <p>The above code will display the data, but it may take some time to display all the data. What I want to do is that, I want to update the scrollView at every loop and display each row after the textview is added to the layout.</p> <p>Please check out <a href="https://play.google.com/store/apps/details?id=com.cleanmaster.mguard" rel="nofollow">this app</a> for the reference.</p> <p>This is the test code that I am doing to achieve what I want. Please have a look:</p> <pre><code>ListView list = (ListView)findViewById(R.id.listView1); ListAdapter adapter = new ListAdapter(this); list.setAdapter(adapter); for(int i=1; i&lt;=10; i++) { adapter.setData(String.valueOf(i)); adapter.notifyDataSetChanged(); } </code></pre> <p>Code for my ListAdapter:</p> <pre><code>public class ListAdapter extends BaseAdapter { private Context context; private int count; private ArrayList&lt;String&gt; data = new ArrayList&lt;String&gt;(); public ListAdapter(Context context) { this.context = context; } @Override public int getCount() { return count; } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } public void setData(String str) { data.add(str); count = data.size(); } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if(convertView == null) { LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.test_layout, parent, false); holder = new ViewHolder(); holder.tv = (TextView)convertView.findViewById(R.id.textView1); convertView.setTag(holder); } else { holder = (ViewHolder)convertView.getTag(); } try { for(int i=0; i&lt;=data.size(); i++) { holder.tv.setText(data.get(i)); } } catch (Exception e) { e.printStackTrace(); } return convertView; } static class ViewHolder { TextView tv; } } </code></pre> <p>Thanks in advance Abhishek</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