In the expanded list view, I have three headers with child views, I want to put custom views for the view in each of the headers, as in one child view. I want to put the grid in the form of images and in another representation for children. I want to place a custom search bar and switches, list view, etc. How to transfer different data from the main activity to each of the child views and how to handle click events of children?
Till now my progress
1.Open list view
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffe0e0e0"
android:layout_weight="0.6">
<ExpandableListView
android:id="@+id/lvExp"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</LinearLayout>
2.custom header names
<?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="55dip"
android:orientation="vertical">
<TextView
android:id="@+id/lblListItem"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="17dip"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="test"
android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"
android:textColor="#ff009992" />
</LinearLayout>
3.grid view
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center" />
4.ExpLSt Adapter
using System;
using Android.Widget;
using System.Collections.Generic;
using Android.App;
using Android.Views;
namespace NEC
{
public class ExpandableListAdapter :BaseExpandableListAdapter
{
private Activity _context;
private List<string> _listDataHeader;
private Dictionary<string, List<string>> _listDataChild;
ImageAdapter imageAdaptor;
public ExpandableListAdapter(Activity context, List<string> listDataHeader,Dictionary<String, List<string>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
public override Java.Lang.Object GetChild (int groupPosition, int childPosition)
{
return _listDataChild[_listDataHeader[groupPosition]][childPosition];
}
public override long GetChildId (int groupPosition, int childPosition)
{
return childPosition;
}
public override View GetChildView (int groupPosition, int childPosition, bool isLastChild, View convertView,ViewGroup parent)
{
if(groupPosition == 0) {
convertView = View.Inflate(_context,Resource.Layout.expandable_Child_Layout, null);
GridView grid = (GridView)convertView.FindViewById(Resource.Id.gridview);
grid.SetAdapter(new ImageAdapter(this._context));
}
if(groupPosition == 1) {
convertView = View.Inflate(_context, Resource.Layout.expandable_child_1_layout, null);
TextView txtView = (TextView) convertView.FindViewById(Resource.Id.lblListItem);
txtView.Text="Test";
txtView.TextSize=15f;
}
if(groupPosition == 2) {
convertView = View.Inflate(_context, Resource.Layout.expandable_child_2_layout, null);
TextView txtView = (TextView) convertView.FindViewById(Resource.Id.lblListItem);
txtView.Text="Test";
txtView.TextSize=15f;
}
convertView.Invalidate();
return convertView;
}
public override int GetChildrenCount (int groupPosition)
{
return _listDataChild [_listDataHeader [groupPosition]].Count;
}
public override Java.Lang.Object GetGroup (int groupPosition)
{
return _listDataHeader[groupPosition];
}
public override int GroupCount {
get {
return _listDataHeader.Count;
}
}
public override long GetGroupId (int groupPosition)
{
return groupPosition;
}
public override View GetGroupView (int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
{
string headerTitle = (string) GetGroup(groupPosition);
if (convertView == null) {
convertView =_context.LayoutInflater.Inflate(Resource.Layout.HeaderCustomLayout,null);
}
TextView lblListHeader = (TextView)convertView.FindViewById (Resource.Id.lblListHeader);
lblListHeader.SetTypeface(null, Android.Graphics.TypefaceStyle.Bold);
lblListHeader.Text=headerTitle;
return convertView;
}
public override bool HasStableIds {
get {
return false;
}
}
public override bool IsChildSelectable (int groupPosition, int childPosition)
{
return true;
}
class ViewHolderItem :Java.Lang.Object
{
}
}
}
5.ImageAdapter
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace NEC
{
[Activity (Label = "ImageAdaptor")]
public class ImageAdapter : BaseAdapter
{
Context context;
public ImageAdapter (Context c)
{
context = c;
}
public override int Count {
get { return thumbIds.Length; }
}
public override Java.Lang.Object GetItem (int position)
{
return null;
}
public override long GetItemId (int position)
{
return 0;
}
public override View GetView (int position, View convertView, ViewGroup parent)
{
ImageView imageView;
if (convertView == null) {
imageView = new ImageView (context);
imageView.LayoutParameters = new GridView.LayoutParams (85, 85);
imageView.SetScaleType (ImageView.ScaleType.CenterCrop);
imageView.SetPadding (8, 8, 8, 8);
} else {
imageView = (ImageView)convertView;
}
imageView.SetImageResource (thumbIds[position]);
return imageView;
}
int[] thumbIds = {
Resource.Drawable.sample_2, Resource.Drawable.sample_3,
Resource.Drawable.sample_4, Resource.Drawable.sample_5,
Resource.Drawable.sample_6, Resource.Drawable.sample_7,
Resource.Drawable.sample_0, Resource.Drawable.sample_1,
Resource.Drawable.sample_2, Resource.Drawable.sample_3,
Resource.Drawable.sample_4, Resource.Drawable.sample_5,
Resource.Drawable.sample_6, Resource.Drawable.sample_7,
Resource.Drawable.sample_0, Resource.Drawable.sample_1,
Resource.Drawable.sample_2, Resource.Drawable.sample_3,
Resource.Drawable.sample_4, Resource.Drawable.sample_5,
Resource.Drawable.sample_6, Resource.Drawable.sample_7
};
}
}
6. The main activity
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Support.V7.App;
using toolbar = Android.Support.V7.Widget.Toolbar;
using System.Collections.Generic;
namespace NEC
{
[Activity(Label = "LedgerHome",Theme="@style/AppTheme",ScreenOrientation= Android.Content.PM.ScreenOrientation.Landscape)]
public class Ledger_HomeActivity : AppCompatActivity
{
toolbar mToolbar;
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<string> listDataHeader;
Dictionary<string, List<string>> listDataChild;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
this.Window.AddFlags (WindowManagerFlags.Fullscreen);
SetContentView(Resource.Layout.Ledger_Home);
mToolbar = FindViewById<toolbar>(Resource.Id.app_bar);
SetSupportActionBar(mToolbar);
SupportActionBar.Title = "";
SupportActionBar.SetLogo(Resource.Drawable.TopLeftr_necLogo);
expListView = FindViewById<ExpandableListView>(Resource.Id.lvExp);
FnGetListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
expListView.SetAdapter (listAdapter);
FnClickEvents();
}
void FnClickEvents()
{
expListView.ChildClick+= delegate(object sender, ExpandableListView.ChildClickEventArgs e) {
Toast.MakeText(this,"child clicked",ToastLength.Short).Show();
};
expListView.GroupExpand += delegate(object sender, ExpandableListView.GroupExpandEventArgs e) {
Toast.MakeText(this,"group expanded",ToastLength.Short).Show();
};
expListView.GroupCollapse+= delegate(object sender, ExpandableListView.GroupCollapseEventArgs e) {
Toast.MakeText(this,"group collapsed",ToastLength.Short).Show();
};
}
void FnGetListData() {
listDataHeader = new List<string>();
listDataChild = new Dictionary<string, List<string>>();
listDataHeader.Add("QUICK ITEMS");
listDataHeader.Add("PRODUCT LOOKUP");
listDataHeader.Add("NON MARCHANDISE");
List<string> lstCS = new List<string>();
lstCS.Add("Field Theory");
lstCS.Add("Field Theory");
lstCS.Add("Field Theory");
lstCS.Add("Field Theory");
lstCS.Add("Field Theory");
lstCS.Add("Field Theory");
lstCS.Add("Field Theory");
List<string> lstEC = new List<string>();
lstEC.Add("Field Theory");
lstEC.Add("Logic Design");
lstEC.Add("Analog electronics");
lstEC.Add("Network analysis");
lstEC.Add("Micro controller");
lstEC.Add("Signals and system");
List<string> lstMech = new List<string>();
lstMech.Add("Instrumentation technology");
lstMech.Add("Dynamics of machinnes");
lstMech.Add("Energy engineering");
lstMech.Add("Design of machine");
lstMech.Add("Turbo machine");
lstMech.Add("Energy conversion");
listDataChild.Add(listDataHeader[0], lstCS);
listDataChild.Add(listDataHeader[1], lstEC);
listDataChild.Add(listDataHeader[2], lstMech);
}
}
}