Reputation: 115
I am new to android and I want to add a long list of textViews to a LinearLayout (about 200 textviews).
As you know adding large views to layout causes the Activity to freeze until all of textviews are added. I want to refresh the layout after each addview and show the new textview that is added to the layout. I have tested everything that came to my mind and I've searched all the web for answer and I know that I must use threads, but none of threads worked for me.
I have used ListView but it is too slow because it needs to make so many control invisible when they are out of view.
How can I force a refresh after each view?
Edit:
Here is the layout that is being inflated about 100 times:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pixlui="http://schemas.android.com/apk/com.neopixl.pixlui"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp" >
<com.neopixl.pixlui.components.textview.TextView
android:id="@+id/itemTitle1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text=""
android:textColor="#58595b"
android:textSize="@dimen/details_title_font_size"
pixlui:typeface="font.ttf" />
<JustifiedTextView
android:id="@+id/itemText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:textColor="#58595b"
android:textSize="@dimen/details_font_size"
android:lineSpacingMultiplier="2"/>
</LinearLayout>
And here is getView
method of my BaseAdapter
:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.rowitemview, null);
holder = new ViewHolder();
holder.title1 = (TextView) ((LinearLayout)convertView).getChildAt(0);
holder.text1 = (JustifiedTextView) ((LinearLayout)convertView).getChildAt(1);
holder.text1.SetTextAlign(Align.RIGHT);
holder.text1.setTypeface(font);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
holder.title1.setText(getItem(position).getTitle());
holder.text1.setText(getItem(position).getDesc());
return convertView;
}
The problem with this ListView
is that it is very laggy when scrolling up or down. I even tried lazy loading items, but it didn't work either.
Upvotes: 0
Views: 374
Reputation: 10177
You really need to refactor your code to not add 200 textviews.
What you can do is replace those 200 textviews with one listView. This adds and recycles child views dynamically. So even if you have 200 entries, the app will only occupy itself with what needs to be drawn on the screen.
See listview tutorial.
Upvotes: 3