I am working with custom expandable list view in android. In my expandable list view has items with linear layouts.
You can find my expandable listview here. https://drive.google.com/file/d/0B2NGqFM-F0bNcUZqUlRPaUZYUjg/edit?usp=sharing
In the image the child item is one linearlayout. How can i get individual items like main,wall,table and entry items id. So that i will perform individual operations.
You can find my adapter here.
package com.newsmartcontrol;
import android.content.Context;
import android.database.DataSetObserver;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListAdapter;
import android.widget.TextView;
import com.smartcontrol.R;
public class ExpandsAdapter implements ExpandableListAdapter
{
Context context;
LayoutInflater layoutInflater;
public ExpandsAdapter (Context context, LayoutInflater layoutInflater)
{
this.context = context;
this.layoutInflater = layoutInflater;
}
@Override
public void registerDataSetObserver(DataSetObserver observer) {
// TODO Auto-generated method stub
}
@Override
public void unregisterDataSetObserver(DataSetObserver observer) {
// TODO Auto-generated method stub
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return 4;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return 1;
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return null;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View view, ViewGroup parent)
{
view = View.inflate(context, R.layout.expands_group, null);
TextView title_name = (TextView) view.findViewById(R.id.title_name);
if(groupPosition == 0) {
title_name.setText("Lights");
}
if(groupPosition == 1) {
title_name.setText("AC-Thermostat");
}
if(groupPosition == 2) {
title_name.setText("Drapery");
}
if(groupPosition == 3) {
title_name.setText("TV");
}
view.invalidate();
return view;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View view, ViewGroup parent)
{
if(groupPosition == 0) {
view = View.inflate(context, R.layout.lights_layout, null);
}
if(groupPosition == 1) {
view = View.inflate(context, R.layout.ac_thermostat_layout, null);
}
if(groupPosition == 2) {
view = View.inflate(context, R.layout.drapery_layout, null);
}
if(groupPosition == 3) {
view = View.inflate(context, R.layout.tv_layout, null);
}
view.invalidate();
return view;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean areAllItemsEnabled() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}
@Override
public void onGroupExpanded(int groupPosition) {
// TODO Auto-generated method stub
}
@Override
public void onGroupCollapsed(int groupPosition) {
// TODO Auto-generated method stub
}
@Override
public long getCombinedChildId(long groupId, long childId) {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getCombinedGroupId(long groupId) {
// TODO Auto-generated method stub
return 0;
}
}
And my activity is here.
public class ExpandsMainActivity extends Activity
{
ExpandableListView expandableListView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.expands_main);
expandableListView = (ExpandableListView)findViewById(R.id.list);
ExpandsAdapter adapter = new ExpandsAdapter(this, getLayoutInflater());
expandableListView.setAdapter(adapter);
}
}
Please tell me how can i get individual items of the child sub item id in the expandable listview. So that i will write the click operation for main,wall and remaining all items individually.