I have a list that is organized as follows:
CheckBox,
ImageButton,
LinearLayout{ TextView title, TextView Subtitle}
What I am trying to do is to have three separate clickable areas of the ListItem: the checkbox should be checkable, ImageButton, and the actual list item itself. The checkbox is hidden by default, but can be made visible when a certain button on the list's header is pressed (ie SELECT). I just want a way to select multiple items from the list, and I am not irreversibly set on using hidden checkboxes- if there is a way to do this that would be easier, I would be happy to hear the alternative.
Here is the relevant snippet of my adapter:
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder;
final T t = list.get(position);
if(convertView == null){
convertView = vi.inflate(R.layout.folder_list_item,parent,false);
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.text_view_folder_item);
holder.subtitle = (TextView) convertView.findViewById(R.id.text_view2);
holder.eye = (ImageButton) convertView.findViewById(R.id.folder_vis_button);
holder.check = (CheckBox) convertView.findViewById(R.id.phone);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.title.setText(t.getName());
holder.subtitle.setText(t.getDescription());// = (TextView) convertView.findViewById(R.id.text_view2);
return convertView;
}
And the XML is as follows. As you can see, I have made the individual list items clickable but unfocassable, as recommended in posts I have read about this very problem.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:clickable="true"
android:focusable="true">
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:visibility="invisible"
android:focusable="false"/>
<ImageButton
android:id="#+id/folder_vis_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:scaleType="fitXY"
android:layout_toRightOf="#+id/checkbox"
android:contentDescription="#string/contentDescription"
android:focusable="false"
android:src="#drawable/open_eyeball" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_toRightOf="#id/folder_vis_button"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical"
android:focusable="false"
android:clickable="true">
<TextView
android:id="#+id/text_view_folder_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:focusable="false"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/text_view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:focusable="false"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
Clicking on the list item is handled, if I convert the listitem to actually use on of the built in listitems such as android.R.layout.simple_list_item_1.
However, when I use my own layout, I cannot get click events on the list item itself, just on the image button.
I have tried inflating the view in a different way (int resource, ViewGroup root) ... I have tried working just with the imagebutton, or just with the checkbox, using an imageview instead of an imagebutton, with little in terms of success. Thank you for taking the time to look at this.
Related
I have an application in android which lets you manage your school grades. It is just a project for learning so nothing serious.
Now if you open the details from a subject you can see the grades and edit them. If you then click on save I have to check if something changed or something new was added.
Now my problem is that I don't now how I can get a specific view from a ArrayAdapter or from the ListView because every one of those grade fields are generated by the ArrayAdapter and I have to check them all for changes.
So I have a ArrayAdapter which fills a ListView with the following elements (list_grades_prefab.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10pt"
android:weightSum="2"
android:orientation="horizontal">
<EditText
android:id="#+id/grade_field"
android:textSize="10pt"
android:textAlignment="center"
android:layout_weight="1"
android:layout_marginRight="10pt"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/weight_field"
android:textSize="10pt"
android:textAlignment="center"
android:layout_weight="0.7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_weight="0.3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10pt"
android:textStyle="bold"
android:text="%"/>
</LinearLayout>
Heres the getView of the ArrayAdapter:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder = new ViewHolder();
if(convertView == null){
LayoutInflater layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.list_grades_prefab, null);
viewHolder.GradeField = (EditText) convertView.findViewById(R.id.grade_field);
viewHolder.WeightField = (EditText)convertView.findViewById(R.id.weight_field);
convertView.setTag(viewHolder);
}else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.GradeField.setText(String.valueOf(Grades.get(position)[0]));
viewHolder.GradeField.setTextColor(BasicFunctions.colorFromGrade(Grades.get(position)[0]));
viewHolder.WeightField.setText(String.valueOf(Grades.get(position)[1]).split("\\.")[0]);
return convertView;
}
It just fills the different EditText views with text.
Here I set the ArrayAdapter (GradesAdapter):
ListView gradeListView = (ListView)findViewById(R.id.grade_list_view);
GradesAdapter gradesAdapter = new GradesAdapter(this, R.layout.list_grades_prefab, grades);
gradeListView.setAdapter(gradesAdapter);
grade_list_view is the ListView and grades is an two dimensional array type double.
How do I get now every EditText with the id grade_field from the ArrayAdapter when I am not inside the getView method?
After the user edits the data, call notifyDataSetChanged on your adapter. Since you are using a ListView instead of RecyclerView, that's your only option to inform the views that something changed.
I am using ListView to display some data. The data is shown in TextView. String length which is shown can vary. so the textview which is shown changes its positions depending upon the length of the string. The problem I am facing is
Suppose there are 5 rows. For Row 3 if the text is long, the position of textview showing the text adjusts to show the content. However, textview positions of other rows also changes even if the text is smaller. This has something to do with ListView row caching I am not able to figure out how to reset the row.
Row Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="100dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="#dimen/text_margin_bottom"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/id1"
android:textSize="#dimen/textsize_content3" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/id2"
android:textSize="#dimen/textsize_content3" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="#dimen/text_margin_bottom"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/id3"
android:textSize="#dimen/textsize_content3" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/id4"
android:textSize="#dimen/textsize_content3" />
</LinearLayout>
</LinearLayout>
GetView Code
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
ShowData metaData = getItem(position);
if (convertView == null) {
convertView = inflater.inflate(R.layout.row, parent, false);
holder = new ViewHolder();
holder.id1 = (TextView) convertView
.findViewById(R.id.id1);
holder.id2 = (TextView) convertView
.findViewById(R.id.id2);
holder.id3 = (TextView) convertView
.findViewById(R.id.id3);
holder.id3 = (TextView) convertView
.findViewById(R.id.id4);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
convertView.invalidate();
holder.id1.setText(metaData.id1);
holder.id2.setText(metaData.id2);
holder.id3.setText(metaData.id3);
holder.id4.setText(metaData.id4);
return convertView;
}
How to reset the listview row?
As you mentioned, your TextViews are sizing vertically due to the wrap_content values for their layout_heights. It seems that when Views are recycled in ListViews (and, most likely, all AdapterViews), no layout is automatically triggered, so the TextViews will retain their previous heights. Calling requestLayout() on them will trigger a layout event, during which the TextViews will adjust to their new contents.
How could I create custom ListView like shown in this picture. I know I can make this happen with help of ScrollView and Layouts, but I need to do as a ListView.
Each listview item go over each other.
This may help you
List view with custom view items with partially overlaps (Android)
I have this code like your Requirement. List may overlap by reducing the dividerheight to minus value
<?xml version="1.0" encoding="utf-8"?>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="-5dp"
android:listSelector="#drawable/list_selector" />
Then add background color to adapter according to the position.
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null);
TextView title = (TextView)vi.findViewById(R.id.title); // title
TextView artist = (TextView)vi.findViewById(R.id.artist); // artist name
TextView duration = (TextView)vi.findViewById(R.id.duration); // duration
ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
HashMap<String, String> song = new HashMap<String, String>();
if(position % 2 ==0){
vi.setBackgroundResource(R.drawable.listselector_1);
}else if(position % 3 ==0){
vi.setBackgroundResource(R.drawable.listselector_2);
}else{
vi.setBackgroundResource(R.drawable.listselector_3);
}
song = data.get(position);
// Setting all values in listview
title.setText(song.get(CustomizedListView.KEY_TITLE));
artist.setText(song.get(CustomizedListView.KEY_ARTIST));
duration.setText(song.get(CustomizedListView.KEY_DURATION));
imageLoader.DisplayImage(song.get(CustomizedListView.KEY_THUMB_URL), thumb_image);
return vi;
}
Otherwise you can use listselector images also as your requirement
Thank you guys for trying help me to solve this issue. I look every answer here and finally get i want. I think it will be better I put my code here so maybe someone it will be helpful. The only difference is that my created listview has also shadow in it.
Here is the code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:my_font="http://schemas.android.com/apk/res/com.Helix.android.SmartBonus"
android:orientation="vertical"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
>
<ImageView
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/shadow_bg"
android:visibility="visible"/>
<RelativeLayout
android:id="#+id/secondLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:background="#drawable/drop_shadow"
android:layout_below="#id/imageview">
<ImageView
android:id="#+id/companyImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/secret_logo_small"
android:layout_marginRight="10dp"/>
<TextView
android:id="#+id/companyDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/companyImageView"
android:textColor="#android:color/white"
android:layout_marginTop="7dp"
my_font:ttf_name="300"
android:text="Салон кросаты"/>
<TextView
android:id="#+id/companyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/companyImageView"
android:layout_below="#id/companyDescription"
android:textColor="#android:color/white"
my_font:ttf_name="300"
android:text="Secret"/>
<TextView
android:id="#+id/companyPercentText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:layout_marginTop="7dp"
android:textSize="19sp"
android:layout_marginRight="1dp"
android:layout_toLeftOf="#+id/companyPercent"
my_font:ttf_name="700"
android:text="-20"/>
<TextView
android:id="#id/companyPercent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="#android:color/white"
android:layout_marginTop="7dp"
android:textSize="12sp"
my_font:ttf_name="300"
android:text="%"/>
<ImageView
android:id="#+id/companyPercentImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/companyPercent"
android:layout_marginTop="7dp"
android:textColor="#android:color/white"
android:src="#drawable/percentage_devider"/>
<TextView
android:id="#+id/companyDistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/companyPercentImage"
android:textSize="16dp"
android:textColor="#A57F1C"
my_font:ttf_name="300"
android:text="7m"/>
<LinearLayout
android:id="#+id/checkingButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/companyDistance"
android:layout_marginTop="10dp"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:focusable="false"
android:background="#drawable/green_button_bg"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="16dp"
android:textColor="#android:color/white"
my_font:ttf_name="300"
android:text="Check-in"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textSize="16dp"
android:layout_marginLeft="10dp"
android:textColor="#color/checkin_point_color"
android:layout_weight="1"
my_font:ttf_name="300"
android:text="#string/ten_point"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/slak"
/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
adapter.
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder viewHolder;
final Discount discount = getItem(i);
Discount prev_discount = null;
if (i > 0){
prev_discount = getItem(i-1);
}
if (view == null){
final LayoutInflater li = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.discount_data_item, viewGroup, false);
viewHolder = new ViewHolder();
viewHolder.logo = (ImageView)view.findViewById(R.id.companyImageView);
viewHolder.name = (SmartBonus_TextView)view.findViewById(R.id.companyName);
viewHolder.description = (SmartBonus_TextView)view.findViewById(R.id.companyDescription);
viewHolder.percent = (SmartBonus_TextView)view.findViewById(R.id.companyPercentText);
viewHolder.distance = (SmartBonus_TextView)view.findViewById(R.id.companyDistance);
viewHolder.mainLayout = (RelativeLayout)view.findViewById(R.id.mainLayout);
viewHolder.secondLayaout = (RelativeLayout)view.findViewById(R.id.secondLayout);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
}
if (i == 0){
viewHolder.mainLayout.setBackgroundColor(android.R.color.transparent);
setRoundedBackground(viewHolder.secondLayaout, Color.parseColor(discount.getBackgroundColor()));
} else {
viewHolder.mainLayout.setBackgroundColor(Color.parseColor(prev_discount.getBackgroundColor()));
setRoundedBackground(viewHolder.secondLayaout, Color.parseColor(discount.getBackgroundColor()));
}
return view;
}
private void setRoundedBackground(View view,int color){
final GradientDrawable gradientDrawable = (GradientDrawable) view.getBackground().mutate();
gradientDrawable.setColor(color);
gradientDrawable.invalidateSelf();
}
Here is the result
You should override getView method.
Sample code:
View getView(int position, View convertView, ViewGroup parent){
Object data = getItem(positon);
//usually data object should have type property
if(data.type == TYPE1){
return getLayoutInflater().inflate(R.layout.custom_xml1, null);
}else (data.type == TYPE2){
return getLayoutInflater().inflate(R.layout.custom_xml2, null);
}else{
return getLayoutInflater().inflate(R.layout.custom_xml, null);
}
};
Note:You should reuse convertView object for performance.
Ok, As I have sort of time I manage to write few steps to achieve your task.
1. Make Custom drawable using xml in drawable folder with top corners have radius..
2. Now in your Listview attributes just define negative divider height
Like, android:dividerHeight="-20dp"
3. Set the Custom Drawable as a background of List row in getView().
Also its nice if you able to set color to drawable at dynamically for list row. (In getView() of Custom Adapter).
This what I have achieved from above steps:
I want to display multiple imageview and text view on every row of listview and number of row is not fix (number of rows integer can be fetched from server)
How can i add horizontal scroll view in every row.
i am going to use for loop for number of imageview in getView method is it right way to do that.
My question is how can i inflate horizontal scroll with numbers image views in row in getview method
public View getView(final int position, View convertView,
ViewGroup parent)
{
final ViewHolder viewHolder;
viewHolder = new ViewHolder();
// View vi = convertView;
//if (vi == null)
//{
int Numberofimageview=2;
for(int i=0;i<Numberofimageview;i++)
{
// assume i want to display 2 imageview in every row
LayoutInflater inflater = (LayoutInflater) con
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.my_row_layout, parent,
false);
viewHolder.title = (TextView) convertView.findViewById(R.id.title);
Log.d("myapp", "position" + position);
convertView.setTag(viewHolder);
// }
// else
// {
// viewHolder=(ViewHolder)convertView.getTag();
// }
viewHolder.title.setText(data.get(position));
}
return convertView;
}
This is xml for row
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/wagon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/wagon" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/wagon"
android:layout_centerVertical="true"
android:layout_marginLeft="16dp"
android:src="#drawable/video" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_marginLeft="33dp"
android:layout_toRightOf="#+id/imageView1"
android:text="title of file" />
<TextView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/title"
android:layout_alignRight="#+id/title"
android:layout_marginBottom="18dp"
android:text="type of file" />
Try to include your relativeLayout into a HorizontalScrollView
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout>[...]</RelativeLayout>
</HorizontalScrollView>
Create a custom listview. Create a xml file. within the main linear layout of the xml file put imageview and textview. Make sure the orientation of the linear layout is horizontal.. Make use of that xml file in getview methood
The getView method in my custom ArrayAdapter is getting called multiple times, which I assume it is meant to. Problem is, I have a quantity TextView which is dynamically set but when you scroll and the box goes off screen the value disappears. I am not sure what I am doing wrong and Google is not proving to be much help. Hopefully someone here can help me.
The adapater is called:
adapter = new MenuAdapter(thisActivity, R.layout.menu, list);
setListAdapter(adapter);
My Custom ArrayAdapter:
public MenuAdapter(Context context, int textViewResourceId, ArrayList<Object> menu) {
super(context, textViewResourceId, menu);
this.menu = menu;
vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
Object cat = menu.get(position);
if (cat.getClass().equals(Category.class)) {
v = vi.inflate(R.layout.category, null);
Category item = (Category)cat;
v.setOnClickListener(null);
v.setOnLongClickListener(null);
v.setLongClickable(false);
TextView tt = (TextView) v.findViewById(R.id.category);
tt.setText(item.getName());
} else if (cat.getClass().equals(OrderItem.class)) {
v = vi.inflate(R.layout.menu, null);
OrderItem orderItem = (OrderItem)cat;
Item item = orderItem.getItem();
TextView tt = (TextView) v.findViewById(R.id.title);
tt.setText(item.getName());
TextView bt = (TextView) v.findViewById(R.id.desc);
bt.setText(item.getDescription());
TextView qty = (TextView) v.findViewById(R.id.qty);
qty.setId(item.getId());
ImageButton minus = (ImageButton) v.findViewById(R.id.qtyMinus);
minus.setTag(item);
ImageButton plus = (ImageButton) v.findViewById(R.id.qtyPlus);
plus.setTag(item);
}
return v;
}
The menu layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
android:background="#FFFFFF">
<RelativeLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent"
android:cacheColorHint="#FFFFFF"
android:background="#FFFFFF">
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="16px"
android:textColor="#000000"
/>
<TextView
android:id="#+id/desc"
android:layout_below="#id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="11px"
android:textStyle="italic"
android:textColor="#000000"
/>
</RelativeLayout>
<ImageButton
android:id="#+id/qtyMinus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/minus"
android:paddingTop="15px"
android:onClick="minusQty" />
<TextView
android:id="#+id/qty"
android:layout_width="50px"
android:layout_height="50px"
android:textColor="#000000"
android:textSize="18px"
android:gravity="center_vertical|center_horizontal"
android:freezesText="true"
android:background="#android:drawable/editbox_background"/>
<ImageButton
android:id="#+id/qtyPlus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/plus"
android:paddingTop="15px"
android:onClick="addQty" />
</LinearLayout>
getView() will be called multiple times as you note. It shouldn't matter, because your array adapter is based on the state of it's internal data model (array, list of objects, whatever). getView() should be idempotent in that calling it multiple times shouldn't change the result.
You say "when you scroll and the box goes off screen the value disappears". Note sure what mean. When you scroll one of the views generated in getView() off the visible area, and when you scroll it back, the value is different? without any other information, I'd have to say that's not possible. The reason is again that unless you are modifying the internal state of the adapter, or changing the adapter, you will always generate the same view for a given position.
By the way, convertView can be null, so you want to do something like,
View v = convertView;
if (v == null) {
v = inflater.inflate(...);
}
// now use v in the rest of the method
In your listview set android:height = "match_parent". Now getview called your dataset count. we can reuse the convertview. Check the convertview if it is NULL inflate your view. Otherwise, write your remaining code.
if(convertView ! = null)
{
//rest of your Code
}
else
{
//inflate that view
}