I'm facing a problem that my getView() starts recycling even when the adapter is set in listview for the first time, I have 5 items visible for the first time and due to the requirement i have to set the listview height with a constant value(even though I tried changing to fill_parent but no effect) i have searched and found this same as mine problem link! i have read it thouroughly and came to know that this kind of problem is because the listview height should not be set to wrap_content i have even try that but still no effect my log cat says
I/System.out(17411): getview 0 null
I/System.out(17411): getview 1 android.widget.RelativeLayout@40574ce0
I/System.out(17411): getview 2 android.widget.RelativeLayout@40574ce0
I/System.out(17411): getview 3 android.widget.RelativeLayout@40574ce0
I/System.out(17411): getview 4 android.widget.RelativeLayout@40574ce0
I/System.out(17411): getview 5 android.widget.RelativeLayout@40574ce0
I/System.out(17411): getview 0 android.widget.RelativeLayout@40574ce0
I/System.out(17411): getview 1 null
I/System.out(17411): getview 2 null
I/System.out(17411): getview 3 null
I/System.out(17411): getview 4 null
when adapter is set for the first time, (I didn't even scroll it but still it recycling don't know why) here is my layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/newDramaLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background" >
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="50dp"
android:visibility="gone"
android:background="@drawable/header">
<Button
android:id="@+id/refreshBt"
android:layout_width="55dp"
android:layout_height="50dp"
android:onClick="refresh"
android:layout_alignParentRight="true"
android:background="@drawable/refresh"/>
</RelativeLayout>
<LinearLayout
android:id="@+id/info"
android:layout_width="match_parent"
android:layout_height="30dp"
android:visibility="gone"
android:gravity="center_horizontal"
android:layout_below="@+id/header"
android:background="@drawable/information"
android:paddingLeft="10dp" >
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_marginBottom="5dp"
android:layout_height="wrap_content"
android:text="@string/label"
android:textColor="@android:color/secondary_text_dark" />
</LinearLayout>
<ListView
android:id="@+id/newDramasList"
android:layout_below="@+id/info"
android:cacheColorHint="#00000000"
android:layout_width="match_parent"
android:layout_centerInParent="true"
android:dividerHeight="5dp"
android:divider="@android:color/transparent"
android:layout_height="320dp"
android:visibility="gone">
</ListView>
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_centerInParent="true" />
<LinearLayout
android:id="@+id/footer"
android:layout_below="@+id/newDramasList"
android:layout_width="match_parent"
android:layout_height="50dp"
android:visibility="gone"
android:background="@drawable/footer"/>
</RelativeLayout>
the listview I have try making its height fill_parent but problem still not fixed. here is my code
$@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
System.out.println("getview "+position+" "+convertView);
View row=convertView;
if(row==null)
{
LayoutInflater inflater=((Activity)context).getLayoutInflater();
row=inflater.inflate(layoutResourceId, parent,false);
holder=new NewDramas();
holder.ivIcon=(ImageView)row.findViewById(R.id.dramaIcon);
holder.tvDramaName=(TextView)row.findViewById(R.id.dramaTitle);
holder.tvDate=(TextView)row.findViewById(R.id.date);
row.setTag(holder);
}
else
{
holder=(NewDramas)row.getTag();
}
holder.ivIcon.setImageResource(R.drawable.new_drama_icon);
holder.tvDramaName.setText(dramaList.get(position).getDramaName());
holder.tvDate.setText(dramaList.get(position).getDate());
return row;
}
here is the inflated layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="280dp"
android:layout_height="70dp"
android:orientation="vertical"
android:background="@drawable/new_dramas_list_back" >
<ImageView
android:id="@+id/dramaIcon"
android:layout_width="50dp"
android:layout_height="45dp"
android:src="@drawable/favorite_icon"/>
<Button
android:id="@+id/fav"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/dramaIcon"
android:visibility="gone"
android:focusable="false"
android:layout_alignRight="@+id/dramaIcon"
android:background="@drawable/heart"
/>
<TextView
android:id="@+id/dramaTitle"
android:layout_toRightOf="@+id/dramaIcon"
android:layout_alignTop="@+id/dramaIcon"
android:layout_width="wrap_content"
android:width="150dp"
android:paddingTop="5dp"
android:textColor="@android:color/white"
android:ellipsize="end"
android:layout_marginLeft="32dp"
android:layout_height="wrap_content"
android:text="title"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/updateDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_below="@+id/dramaIcon"
android:layout_alignParentRight="true"
android:layout_marginTop="2dp" >
<TextView
android:id="@+id/updated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="updated:"
android:textColor="#ffff00"
android:layout_alignBottom="@+id/dramaIcon"/>
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffff00"
android:layout_marginLeft="1dp"
android:text="12/08/2102" />
</LinearLayout>
</RelativeLayout>
I also added a button as a footerView in my listview? I hope this ain't the reason of this strange behaviour and some thing strange I have noticed that in logcat the relative id for the getview 1 is same repeating for the 5 times, that means there is problem with position 1 in my list view
can any one please help me understand this weird behaviour, thanks in advance.