I have an application in which i use the listview which have two part one is section part and other part is item part. But i want to make the listview in group with rounded corner depending on sectioned information. Suppose the section part contain the character A, all the information regarding A are display under the sction A with rounded background again if the header contain B then all the information regarding B are display under B with rounded corner and so on. I will give you my adapter class where i want to make the rounded block according to the sectioned information.But i use two different custom view one is for section and second one is for section item. I write the condition in given code which display the block with rounded corner according to the section text. But rounded background shape display only first time when i move the listview it was remove from the background.
in my following code i was mention some condition.So what is do in the condition i explain it.
**variables:**
size- it indicate the how much data contain in a particular sectioned.
index- it indicate the position of the array.
arr- this is an array.
counter- it indicate the position where i set the rounded shape.
This is my adapter class:
public class EntryAdapter extends ArrayAdapter {
private Context context;
public ArrayList items;
private LayoutInflater vi;
public int arr[]=new int[26];
public int sum=0,size,counter=0,index=0;
public EntryAdapter(Context context,ArrayList items,int arr[],int size) {
super(context,0, items);
this.context = context;
this.items = items;
this.arr=arr;
vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.size=size;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewHolder1 holder1=new ViewHolder1();
final Item i = (Item) items.get(position);
if (i != null) {
if(i.isSection()){
SectionItem si = (SectionItem)i;
v = vi.inflate(R.layout.list_item_section, null);
v.setOnClickListener(null);
v.setOnLongClickListener(null);
v.setLongClickable(false);
holder1.sectionView = (TextView) v.findViewById(R.id.list_item_section_text);
holder1.sectionView.setText(si.getTitle());
}else{
EntryItem ei = (EntryItem)i;
if (v!=null) {
v = vi.inflate(R.layout.list_item_entry, null);
holder1.title = (TextView)v.findViewById(R.id.list_item_entry_title);
holder1.ll=(LinearLayout)v.findViewById(R.id.ll);
}
counter++;
holder1.title.setText(ei.title);
if(counter==arr[index])
{
counter=0;
if(index<size){
index++;
}
holder1.ll.setBackgroundResource(R.drawable.list_rounded_corner_shape);
Log.v("LOG ", "if ");
}
}
}
return v;
}
class ViewHolder1{
TextView sectionView,title;
LinearLayout ll;
}
}
Tiada ulasan:
Catat Ulasan