android
Custom Listview : span listitems on selection
First of all I apologize for not posting any code on what I have done.But I am not getting the point from where and how to start customize listview. Question : I have to create a listview in which based on the selection adjacent listitems shall merge. I googled but couldn't find any relevant information. Please help me. Please see the attached image. See this image..it shows rounded corner background of listitems Default list is the list with some custom adapter and second image shows what is expected.
It is bit tricky but i think the best possible solution for this problem is listView inside a listView. Now let me explain, There should be two list view LV1 (ExtendedHeightListView) : It will have height equal to the height of all items (obviously view will not recycle in this listview). We will use it as a item for main list view. public class ExtendedHeightListView extends ListView { boolean expanded = false; public ExtendedHeightListView(Context context) { super(context); } public ExtendedHeightListView(Context context, AttributeSet attrs) { super(context, attrs); } public ExtendedHeightListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public boolean isExpanded() { return expanded; } public void setExpanded(boolean expanded) { this.expanded = expanded; } #Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { if (isExpanded()) { // Calculate entire height by providing a very large height hint. // But do not use the highest 2 bits of this integer; those are // reserved for the MeasureSpec mode. int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); android.view.ViewGroup.LayoutParams params = getLayoutParams(); params.height = getMeasuredHeight(); } else { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } LV2 (Default ListView) : Main ListView have items as extended height list view. (It is normal list view so your small list views will recycle). Now considering you have data in grouped manner. Say G1 - 2 items, G2 - 5 items, G3 - 1 item BaseAdapter(BA1) for ExtendedHeightListView (LV1) : public void BA1(Context context, Grp g) { this.context = context; this.grp = g; } public int getCount() { return grp.getNumberOfItems(); } public View getView(int position, ... ) { // write here your normal getView; } BaseAdapter(BA2) for Main ListView (LV2) : pass G1, G2 and G3 to the adapter. public int getCount() { return 3; //Number of groups } public View getView (int position, ... ) { if (convertView == null) { convertView = inflate LV1; } ExtendedHeightListView lv1 = convertView.findViewById(R.id.lv1); Grp g = getGroup(position); BA1 adapter = new BA1 (context, g); //If background of each group is different lv1.setBackgroundResource(R.drawable.bg); lv1.setAdapter (adapter); return convertView; } And set your OnItemClickListener on Main ListView (LV2). I think it will help...
Related Links
“Android Design Icons” do not match system icons
Translucent one time startup activity
Removing Border from ListView
I want 1 Spinner dependent on another spinner item
Android Error: Binary XML file line #16: Error inflating class fragment when adding map fragment
phonegap android datepicker plugin not working on second field
remove the Video view's Seekbar in android
You uploaded an APK that is signed with a different certificate to your previous APKs [duplicate]
Wrap include around views [closed]
how to link face detector api with the photo activity
How to create a customized Soft keyboard with my own set of images
How to get connected device count in hotspot(AP) programmatically [Android]
Android project in Eclipse is missing the Android 4.2.2 library folder
Phonegap Android InAppBrowser not working
Failed to load map. Error contacting Google servers on fragment
String questionText=“Hello good evenin${b}${u} Amit is the best ${/u}${/b} and he loves singing”; [closed]