Update As suggested i have added data view holder into my code but still i am facing same problem. I have edited my question and my code please take a look at that.
I want to display 2 view in my List view according to row number.I want to display right hand train engine on 1st row and left hand train engine on 2nd row and vice versa.
To have vice versa row view change I put if condition and check position by mod%2==0 than even otherwise odd.. but when i launch app i get exact left right left right view But when i scroll down i got two right hand train engine row one after another.
Here is Code
public LazyAdapter(Activity a, ArrayList<String> songsList) {
activity = a;
data=songsList;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
Log.d("Listview","Count is"+data.size());
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
Log.d("position is - ", "position is "+position);
if(position%2==0)
{
return 0;
}
else
{
return 1;
}
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int type = getItemViewType(position);
System.out.println("getView " + position + " " + convertView + " type = " + type);
if (convertView == null) {
holder = new ViewHolder();
switch (type) {
case 0:
convertView = inflater.inflate(R.layout.list_row1, null);
holder.caption = holder.caption = ((ImageView)convertView.findViewById(R.id.train).findViewById(R.id.boogi1).findViewById(R.id.imageView1));
break;
case 1:
convertView = inflater.inflate(R.layout.list_row2, null);
holder.caption = holder.caption = ((ImageView)convertView.findViewById(R.id.train2).findViewById(R.id.boogi2).findViewById(R.id.imageView1));
break;
}
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
return convertView;
}
static class ViewHolder {
ImageView caption;
}
List_row1.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="500dp"
android:background="@drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip" >
<include android:id="@+id/mainview" layout="@layout/activity_main" />
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<include android:id="@+id/train" layout="@layout/train" />
</HorizontalScrollView>
train.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<include android:id="@+id/boogi1" layout="@layout/boogi" />
<include android:id="@+id/boogi2" layout="@layout/boogi" />
<include android:id="@+id/engine" layout="@layout/engine" />
In Train2.xml Include tag order is changed.