I am trying to show a gridview with text in it , basically it will be showing 7-8 values against every day of the year . so yes it gets pretty large pretty quickly.
And when i try to scroll down and i am in the middle , it runs out of memory.
here is how i am trying to do it
public View getView(int position, View convertView, ViewGroup parent) {
dateView = new TextView(mContext);
dateView.setText(dateArray.get(position));
dateView.setSingleLine(true);
// dateview.setLayoutParams(new GridView.LayoutParams(70, 70));
Log.d("--in get view--", "");
return dateView;
}
Is there any better way to do it , like may be releasing the view which are not showing in the screen at the moment?
You should reuse views. Now you create new instance of
TextViewevery timegetViewcalled. But you’re givenconvertView. Android caches all views for you and reuse them, so instead of having 1000 views for every row it uses about 10-20 (how many visible on screen) views and reuse them. You should check first ifconvertViewis not null then cast it toTextViewand populate with your text otherwise you need to createTextViewmanually as you’re doing now and return it. Check this tutorial: http://www.vogella.com/articles/AndroidListView/article.html 5.2 ConvertView.