AndroidMultilevel expandableListView, 4th level - java

I'm struggling with multilevel Expandable ListViews. I manage to make a 3 level Expandable ListView it is to say :
-- GrandParent
--- Parent
----- Child
But whenever I try to add a 4th sub child, the view seems to appear behind the last level. Here are the elements I use to achieve this :
CustomExpandableListView.java
public class CustomExpandableListView extends ExpandableListView {
public CustomExpandableListView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public CustomExpandableListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomExpandableListView(Context context) {
super(context);
}
#Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(2000, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
#Override
protected void onDetachedFromWindow() {
try {
super.onDetachedFromWindow();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
ExpandableListAdapter.java
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> listDataHeader; // header titles
private HashMap<String, List<ExpandableItem>> listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<ExpandableItem>> listChildData) {
this.context = context;
this.listDataHeader = listDataHeader;
this.listDataChild = listChildData;
}
#Override
public Object getChild(int groupPosition, int childPosititon) {
return this.listDataChild.get(this.listDataHeader.get(groupPosition))
.get(childPosititon);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition).getNumberOfChildren() > 0) {
DPPCustomExpandableListView subList = new DPPCustomExpandableListView(context);
List<ExpandableItem> list = listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition).getItems();
ArrayList<String> headers = new ArrayList<String>();
HashMap<String, List<ExpandableItem>> newMap = new HashMap<>();
String name = "Expandable";
headers.add(name);
newMap.put(name, list);
MultiExpandableListAdapter multiAdapter = new MultiExpandableListAdapter(context, headers, newMap);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
subList.setLayoutParams(params);
subList.setAdapter(multiAdapter);
MySalesFragment currentFragment = (MySalesFragment) ((MainActivity) context).getFragmentManager().findFragmentById(R.id.container);
if (currentFragment.getCurrentPagerFragment().getClass().equals(SalesDeclarationFragment.class)) {
SalesDeclarationFragment salesDeclarationFragment = (SalesDeclarationFragment) currentFragment.getCurrentPagerFragment();
subList.setOnChildClickListener(salesDeclarationFragment);
}
return subList;
}
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.sales_declaration_expandable_listview_item, null);
TextView txtListChild = (TextView) convertView
.findViewById(R.id.child_textview);
//txtListChild.setText(childText);
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return this.listDataChild.get(this.listDataHeader.get(groupPosition))
.size();
}
#Override
public Object getGroup(int groupPosition) {
List<ExpandableItem> items = listDataChild.get(listDataHeader.get(groupPosition));
return items;
}
#Override
public int getGroupCount() {
return this.listDataHeader.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.sales_declaration_expandable_list_view_group_header, null);
}
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
MultiExpandableListAdapter.java
public class MultiExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<String> listDataHeader; // header titles
private HashMap<String, List<ExpandableItem>> listDataChild;
public static int count = 0;
public MultiExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<ExpandableItem>> listChildData) {
this.context = context;
this.listDataHeader = listDataHeader;
this.listDataChild = listChildData;
}
#Override
public Object getChild(int groupPosition, int childPosititon) {
return this.listDataChild.get(this.listDataHeader.get(groupPosition))
.get(childPosititon);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if(listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition).getNumberOfChildren() > 0) {
subList = new DPPNLevelCustomEpandableListView(context);
List<ExpandableItem> list = listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition).getItems();
ArrayList<String> headers = new ArrayList<String>();
HashMap<String, List<ExpandableItem>> newMap = new HashMap<>();
headers.add(name);
newMap.put(name, list);
MultiExpandableListAdapter multiAdapter = new MultiExpandableListAdapter(context, headers, newMap);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
subList.setLayoutParams(params);
subList.setAdapter(multiAdapter);
subList.setBackgroundColor(context.getResources().getColor(R.color.loyalty_store_theme_yellow));
MySalesFragment currentFragment = (MySalesFragment)((MainActivity)context).getFragmentManager().findFragmentById(R.id.container);
if (currentFragment.getCurrentPagerFragment().getClass().equals(SalesDeclarationFragment.class)) {
SalesDeclarationFragment salesDeclarationFragment = (SalesDeclarationFragment)currentFragment.getCurrentPagerFragment();
subList.setOnChildClickListener(salesDeclarationFragment);
}
return subList;
}
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.sales_declaration_expandable_listview_item, null);
convertView.setBackgroundColor(context.getResources().getColor(R.color.cpb_blue));
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
int count = this.listDataChild.get(listDataHeader.get(groupPosition)).size();
return count;
}
#Override
public Object getGroup(int groupPosition) {
List<ExpandableItem> items = listDataChild.get(listDataHeader.get(groupPosition));
return items;
}
#Override
public int getGroupCount() {
return this.listDataHeader.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.sales_declaration_expandable_listview_item, null);
convertView.setBackgroundColor(context.getResources().getColor(R.color.cpb_green));
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
ExpandableItem.java
public interface ExpandableItem {
int getNumberOfChildren();
ArrayList<ExpandableItem> getItems();
void addExpandableItem(ExpandableItem item);
String getName();
}
ListTextItem.java
public class ListTextItem implements ExpandableItem{
private ArrayList<ExpandableItem> items;
private String name;
public ListTextItem(String name){
this.name = name;
items = new ArrayList<ExpandableItem>();
}
#Override
public int getNumberOfChildren() {
return items.size();
}
public ArrayList<ExpandableItem> getItems() {
return items;
}
public void addExpandableItem(ExpandableItem itemToAdd) {
items.add(itemToAdd);
}
public String getName() {
return name;
}
}
ExampleFragment.java
public class ExampleFragment extends Fragment implements ExpandableListView.OnChildClickListener {
private View root;
ExpandableListAdapter listAdapter;
#InjectView(R.id.sales_declaration_list)
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<ExpandableItem>> listDataChild;
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
this.root = inflater.inflate(R.layout.fragment_sales_declaration, container, false);
ButterKnife.inject(this, root);
return root;
}
#Override
public void onStart() {
super.onStart();
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
expListView.setGroupIndicator(null);
expListView.setDividerHeight(0);
expListView.setOnChildClickListener(this);
}
#Override
public void onDetach() {
super.onDetach();
}
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<ExpandableItem>>();
// Adding child data
listDataHeader.add("Top 250");
listDataHeader.add("Now Showing");
listDataHeader.add("Coming Soon..");
// Adding child data
List<ExpandableItem> top250 = new ArrayList<ExpandableItem>();
top250.add(new ListTextItem("The Shawshank Redemption"));
top250.add(new ListTextItem("The Godfather"));
top250.add(new ListTextItem("The Godfather: Part II"));
top250.add(new ListTextItem("Pulp Fiction"));
top250.add(new ListTextItem("The Good, the Bad and the Ugly"));
top250.add(new ListTextItem("The Dark Knight"));
top250.add(new ListTextItem("12 Angry Men"));
List<ExpandableItem> nowShowing = new ArrayList<ExpandableItem>();
nowShowing.add(new ListTextItem("The Conjuring"));
nowShowing.add(new ListTextItem("Despicable Me 2"));
nowShowing.add(new ListTextItem("Turbo"));
nowShowing.add(new ListTextItem("Grown Ups 2"));
nowShowing.add(new ListTextItem("Red 2"));
nowShowing.add(new ListTextItem("The Wolverine"));
nowShowing.add(new ListTextItem("The Wolverine2"));
nowShowing.add(new ListTextItem("The Wolverine3"));
nowShowing.add(new ListTextItem("The Wolverine4"));
List<ExpandableItem> comingSoon = new ArrayList<ExpandableItem>();
comingSoon.add(new ListTextItem("2 Guns"));
comingSoon.add(new ListTextItem("The Smurfs 2"));
comingSoon.add(new ListTextItem("The Spectacular Now"));
comingSoon.add(new ListTextItem("The Canyons"));
comingSoon.add(new ListTextItem("Europa Report"));
for(ExpandableItem item : comingSoon) {
top250.get(1).addExpandableItem(item);
}
for(ExpandableItem item : nowShowing) {
top250.get(1).getItems().get(0).addExpandableItem(item);
}
for(ExpandableItem item : comingSoon) {
top250.get(3).addExpandableItem(item);
}
listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
listDataChild.put(listDataHeader.get(1), nowShowing);
listDataChild.put(listDataHeader.get(2), comingSoon);
}
#Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if(!(((ExpandableItem)parent.getExpandableListAdapter().getChild(groupPosition, childPosition)).getNumberOfChildren() > 0)){
//Toast.makeText(getActivity(), listAdapter.getChild(groupPosition, childPosition).toString(), Toast.LENGTH_SHORT).show();
LSFragmentManager fragmentManager = new LSFragmentManager(getActivity());
fragmentManager.showFragment(Fragment2.class.getName());
}
return false;
}
}
Sorry For the long post, hope someone can help me!

Related

Problem with an ExpandableList with 3 level

I have a problem with my ExpendableList. I am trying
to make a 3 level expandablelist. The display on the 3 levels works
fine and stays tidy as it should. But I don't know why, the
subcategories are duplicated. Here is the whole code with the adapter
and the creation of my HashMap. If you have an idea where this comes
from you would help me a lot!
public HashMap<String, HashMap<String, ArrayList<String>>>typeItemList;
public HashMap<String, ArrayList<String>>materiauItemList;
public HashMap<String, HashMap<String, HashMap<String, ArrayList<String>>>> familleItemList;
private ExpandableListView expandableListView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<String> famille = new ArrayList<>();
ArrayList<String> type= new ArrayList<>();
ArrayList<String> materiaux = new ArrayList<>();
familleItemList = new HashMap<>();
for(int g = 1; g<=5; g++) {
famille.add("famille "+g);
HashMap<String, HashMap<String, ArrayList<String>>> typeItemList1 = new HashMap<>();
for (int h = 1; h <= 4; h++) {
type.add("type " + g+h);
HashMap<String, ArrayList<String>> matItemList = new HashMap<>();
for (int i = 1; i <= 4; i++) {
materiaux.add("materiau " + g+h+i);
ArrayList<String> outils = new ArrayList<>();
for (int j = 1; j <= 10; j++) {
outils.add("outils " + g+h+i+j);
}
matItemList.put("materiau " + i, outils);
}
typeItemList1.put("type " + h, matItemList);
}
familleItemList.put("famille "+g, typeItemList1);
}
expandableListView = (ExpandableListView) findViewById(R.id.mainList);
expandableListView.setAdapter(new ParentLevel(this,familleItemList, famille ));
}
public class ParentLevel extends BaseExpandableListAdapter {
private Context context;
ArrayList<String> famille;
HashMap<String, HashMap<String, HashMap<String, ArrayList<String>>>> familleItemList;
public ParentLevel(Context context, HashMap<String, HashMap<String, HashMap<String, ArrayList<String>>>> familleItemList, ArrayList<String> famille ) {
this.context = context;
this.familleItemList = familleItemList;
this.famille=famille;
}
//
#Override
public int getGroupCount() {
return famille.size();
}
#Override
public int getChildrenCount(int i) {
return familleItemList.get(famille.get(i)).size();
}
#Override
public Object getGroup(int i) {
return famille.get(i);
}
#Override
public Object getChild(int i, int i1) {
return familleItemList.get(famille.get(i)).get(i1);
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
#Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
SecondLevelExpandableListView secondLevelELV = new SecondLevelExpandableListView(MainActivity.this);
ArrayList<String> list = new ArrayList<>();
for (String i : Objects.requireNonNull(familleItemList.get(famille.get(groupPosition))).keySet()) {
list.add(i);}
typeItemList = new HashMap<>();
typeItemList=familleItemList.get(getGroup(groupPosition));
secondLevelELV.setAdapter(new SecondLevelAdapter(context, typeItemList,list ));
secondLevelELV.setGroupIndicator(null);
return secondLevelELV;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row_first, null);
TextView text = (TextView) convertView.findViewById(R.id.eventsListEventRowText);
String sGroup = String.valueOf(getGroup(groupPosition));
text.setText(sGroup);
}
return convertView;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
public static class SecondLevelExpandableListView extends ExpandableListView {
public SecondLevelExpandableListView(Context context) {
super(context);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//999999 is a size in pixels. ExpandableListView requires a maximum height in order to do measurement calculations.
heightMeasureSpec = MeasureSpec.makeMeasureSpec(999999, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public class SecondLevelAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<String> type;
private HashMap<String, HashMap<String, ArrayList<String>>> typeItemList;
public SecondLevelAdapter(Context context,HashMap<String, HashMap<String, ArrayList<String>>> typeItemList, ArrayList<String> type) {
this.context = context;
this.typeItemList = typeItemList;
this.type=type;
}
#Override
public int getGroupCount() {
return type.size();
}
#Override
public int getChildrenCount(int i) {
return typeItemList.get(type.get(i)).size();
}
#Override
public Object getGroup(int i) {
return type.get(i);
}
#Override
public Object getChild(int i, int i1) {
return typeItemList.get(type.get(1)).get(i1);
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row_third, null);
TextView text = (TextView) convertView.findViewById(R.id.eventsListEventRowText);
String sGroup = String.valueOf(getGroup(groupPosition));
text.setText(sGroup);
}
return convertView;
}
#Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ThirdLevelExpandableListView thridLevelELV = new ThirdLevelExpandableListView(MainActivity.this);
ArrayList<String> list = new ArrayList<>();
for (String i : typeItemList.get(getGroup(groupPosition)).keySet() ){
list.add(i);}
materiauItemList=new HashMap<>();
materiauItemList = typeItemList.get(getGroup(groupPosition));
thridLevelELV.setAdapter(new ThirdLevelAdapter(context,materiauItemList,list));
thridLevelELV.setGroupIndicator(null);
return thridLevelELV;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
public static class ThirdLevelExpandableListView extends ExpandableListView {
public ThirdLevelExpandableListView(Context context) {
super(context);
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//999999 is a size in pixels. ExpandableListView requires a maximum height in order to do measurement calculations.
heightMeasureSpec = MeasureSpec.makeMeasureSpec(99999, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
public static class ThirdLevelAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<String> materiau;
private HashMap<String, ArrayList<String>> materiauItemList;
public ThirdLevelAdapter(Context context,HashMap<String, ArrayList<String>> materiauItemList,ArrayList<String> materiau) {
this.context = context;
this.materiauItemList = materiauItemList;
this.materiau = materiau;
}
#Override
public Object getGroup(int groupPosition) {
return materiau.get(groupPosition);
}
#Override
public int getGroupCount() {
return materiau.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row_four, null);
TextView text = (TextView) convertView.findViewById(R.id.eventsListEventRowText);
text.setText(String.valueOf(getGroup(groupPosition)));
}
return convertView;
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return materiauItemList.get(materiau.get(groupPosition)).get(childPosition);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row_second, null);
TextView text = (TextView) convertView.findViewById(R.id.eventsListEventRowText);
String outils = String.valueOf(getChild(groupPosition, childPosition));
text.setText(outils);
}
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return materiauItemList.get(materiau.get(groupPosition)).size();
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
}
[family photo displayed correctly][1] [photo of repeating types][2]
[photo of tools that are also repeated][3]
Thank you for your feedback.
[1]: https://i.stack.imgur.com/8TiQa.png [2]:
https://i.stack.imgur.com/LOMol.png [3]:
https://i.stack.imgur.com/hdFAE.png

how to show different hints in editext programmatically

I am using an expandible view where parent is a text view and children are edittext views. I want to show different hints for different edit texts. I tried to do it programmatically but no success at all. Here is my code.
ContactFragment.java
public class ContactFragment extends Fragment {
private View mView;
Context mContext;
EditText edittext;
ExpandableListAdapter listAdapter;
ExpandableListView elv;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = getActivity();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_contact_details, container, false);
ExpandableListView elv = (ExpandableListView) mView.findViewById(R.id.list);
prepareListData();
listAdapter = new ExpandableListAdapter(mContext, listDataHeader,listDataChild);
elv.setAdapter(listAdapter);
elv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// Toast.makeText(getApplicationContext(),
// "Group Clicked " + listDataHeader.get(groupPosition),
// Toast.LENGTH_SHORT).show();
return false;
}
});
// Listview Group expanded listener
elv.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
#Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(mContext,
listDataHeader.get(groupPosition) + " Expanded",
Toast.LENGTH_SHORT).show();
}
});
// Listview Group collasped listener
elv.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(mContext,
listDataHeader.get(groupPosition) + " Collapsed",
Toast.LENGTH_SHORT).show();
}
});
// Listview on child click listener
elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
Toast.makeText(
mContext,
listDataHeader.get(groupPosition)
+ " : "
+ listDataChild.get(
listDataHeader.get(groupPosition)).get(
childPosition), Toast.LENGTH_SHORT)
.show();
return false;
}
});
return mView;
}
/*
* Preparing the list data
*/
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
// Adding child data
listDataHeader.add("Contact Details");
// Adding child data
List<String> basic = new ArrayList<String>();
basic.add(" ");
basic.add(" ");
basic.add(" ");
basic.add(" ");
basic.add(" ");
listDataChild.put(listDataHeader.get(0), basic); // Header, Child data
}
}
ExpandableListAdapter.java
public class ExpandableListAdapter extends BaseExpandableListAdapter implements TextWatcher{
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
private ArrayList<EditText> editTextList = new ArrayList<EditText>();
int i=1;
String name,purpose;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
#Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.fragment_contact_details_child, null);
}
EditText editetext = (EditText) convertView .findViewById(R.id.item);
while(i<6)
{
switch (i)
{
case 1:editetext.setHint("Contact Person");
break;
case 2:editetext.setHint("Contact Person Photo");
break;
case 3:editetext.setHint("Designation/Job");
break;
case 4:editetext.setHint("CEO Name");
break;
case 5:editetext.setHint("Company Name");
break;
}
i++;
}
editetext.addTextChangedListener(this);
editTextList.add(editetext);
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
#Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
#Override
public int getGroupCount() {
return this._listDataHeader.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.fragment_contact_details_parent, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.textViewParent);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
name=editTextList.get(0).getText().toString();
purpose=editTextList.get(1).getText().toString();
}
#Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
System.out.println("Name is"+name);
System.out.println("purpose is"+purpose);
}
}
In your ExpandableListAdapter class under getChildView it looks like you are telling the app to loop through all of the hints and it finishes on "Company Name"
maybe change
while(i<6)
{
switch (i)
{
case 1:editetext.setHint("Contact Person");
break;
case 2:editetext.setHint("Contact Person Photo");
break;
case 3:editetext.setHint("Designation/Job");
break;
case 4:editetext.setHint("CEO Name");
break;
case 5:editetext.setHint("Company Name");
break;
}
i++;
}
to
switch (childPosition)
{
case 1:editetext.setHint("Contact Person");
break;
case 2:editetext.setHint("Contact Person Photo");
break;
case 3:editetext.setHint("Designation/Job");
break;
case 4:editetext.setHint("CEO Name");
break;
case 5:editetext.setHint("Company Name");
break;
}
actual i have better solution why dont u simply use xml code to put hint in your edit text.It will be easy for u and it is not mendetory to code it programmatically.hope u get it

Android, Expandable List View Delete child on Button click

I have implemented a Expandable List View,in Android , you can see in the screenshot , it is working fine , and in Expandable List i have multiple child with delete option in group as you can see in the screen shot, i want to delete a particular child which user has selected to delete , I am not able to delete the child form Expandable List , i will post my code , please anyone guide me
public class PendingFragment extends Fragment {
private AnimatedExpandableListView listView;
private PendingAdapter adapter;
CoordinatorLayout coordinatorLayout;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_pending, container, false);
coordinatorLayout = (CoordinatorLayout)view.findViewById(R.id.pending_frag_coordinatorLayout);
List<GroupItem> items = new ArrayList<GroupItem>();
// Populate our list with groups and it's children
for(int i = 1; i < 10; i++) {
GroupItem item = new GroupItem();
item.title = "GroupItem " + i;
for(int j = 0; j < i; j++) {
ChildItem child = new ChildItem();
child.title = "ChildItem " + j;
item.items.add(child);
}
items.add(item);
}
adapter = new PendingAdapter(getActivity());
adapter.setData(items);
listView = (AnimatedExpandableListView)view.findViewById(R.id.pending_explistView);
listView.setAdapter(adapter);
return view;
}
}
My Listview Adapter
public class PendingAdapter extends AnimatedExpandableListView.AnimatedExpandableListAdapter {
private LayoutInflater inflater;
private List<GroupItem> items;
ListPopupWindow listPopupWindow;
String[] products = {"Delete"};
Context contexts;
public PendingAdapter(Context context) {
inflater = LayoutInflater.from(context);
this.contexts = context;
}
public void setData(List<GroupItem> items) {
this.items = items;
}
private class ChildHolder {
TextView title;
ImageView option_menu;
}
private class GroupHolder {
TextView title;
}
#Override
public ChildItem getChild(int groupPosition, int childPosition) {
return items.get(groupPosition).items.get(childPosition);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getRealChildView(final int groupPosition,final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ChildHolder holder;
ChildItem item = getChild(groupPosition, childPosition);
Log.e("groupPosition=" + groupPosition, "childPosition=" + childPosition);
if (convertView == null) {
holder = new ChildHolder();
convertView = inflater.inflate(R.layout.expchildlistview, parent, false);
holder.title = (TextView) convertView.findViewById(R.id.txtListChild);
holder.option_menu = (ImageView) convertView.findViewById(R.id.checkin_option_menu);
convertView.setTag(holder);
} else {
holder = (ChildHolder) convertView.getTag();
}
holder.title.setText(item.title);
holder.option_menu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ShowListMenu(view,groupPosition, childPosition);
}
});
return convertView;
}
public void ShowListMenu(View v, final int childPosition, final int groupPosition){
listPopupWindow = new ListPopupWindow(contexts);
listPopupWindow.setAdapter(new ArrayAdapter(contexts, android.R.layout.simple_list_item_1, products));
listPopupWindow.setAnchorView(v);
if (Utils.device_width(contexts) >= 320 && Utils.device_width(contexts) < 480) {
//Log.v(">= 320 < 480=", ">= 320 < 480");
listPopupWindow.setWidth(150);
}else if (Utils.device_width(contexts) >= 480 && Utils.device_width(contexts) < 500) {
//Log.v(">= 480=", "< 500");
listPopupWindow.setWidth(150);
}else{
listPopupWindow.setWidth(200);
}
listPopupWindow.setModal(true);
listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Log.v("item.remove=", "" + items.get(groupPosition).items.get(childPosition));
items.get(groupPosition).items.remove(childPosition);
notifyDataSetChanged();
listPopupWindow.dismiss();
}
});
listPopupWindow.show();
}
#Override
public int getRealChildrenCount(int groupPosition) {
return items.get(groupPosition).items.size();
}
#Override
public GroupItem getGroup(int groupPosition) {
return items.get(groupPosition);
}
#Override
public int getGroupCount() {
return items.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
GroupHolder holder;
GroupItem item = getGroup(groupPosition);
if (convertView == null) {
holder = new GroupHolder();
convertView = inflater.inflate(R.layout.explist_group, parent, false);
holder.title = (TextView) convertView.findViewById(R.id.lblListHeader);
convertView.setTag(holder);
} else {
holder = (GroupHolder) convertView.getTag();
}
holder.title.setText(item.title);
return convertView;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public boolean isChildSelectable(int arg0, int arg1) {
return true;
}
}
public class GroupItem {
public String title;
public List<ChildItem> items = new ArrayList<ChildItem>();
}
public class ChildItem {
public String title;
}
Cant see items.remove(child) on click on delete. I think you should try deleting the child from the list and than set the adapter with updated values. #Achin

How to add different image for each group in expandable Listview

In my Expandable Listview, have three groups. I want to add different three image for that group. i tried many codes, but not working.
My code:
Main Activity:
HashMap<String, List<String>> rightDrawerListDetail = getData();
List<String> rightDrawerListTitle = new ArrayList<String>(rightDrawerListDetail.keySet());
adapterR = new CustomExpandableListAdapter(this, rightDrawerListTitle,rightDrawerListDetail);
mRightDrawerList.setAdapter(adapterR);
private HashMap<String, List<String>> getData(){
HashMap<String, List<String>> expandableListDetail = new HashMap<String, List<String>>();
ArrayList<String> arrayList = mydb.getAllAddress();
List asRider = new ArrayList();
asRider.add("hello");
List asRidee = new ArrayList();
asRidee.add("hai");
List recent = new ArrayList();
recent.add("Success");
expandableListDetail.put("As a Rider",asRider);
expandableListDetail.put("As a Ridee",asRidee);
expandableListDetail.put("My Recent Activities",recent);
return expandableListDetail;
}
CustomExpandableListAdapter.java:
public class CustomExpandableListAdapter extends BaseExpandableListAdapter {
private Context mContext;
private List<String> mGroups;
private LayoutInflater mInflater;
private HashMap<String, List<String>> mexpandableListDetail;
public CustomExpandableListAdapter(Context context, List<String> groups,HashMap<String, List<String>> expandableListDetail) {
mContext = context;
mGroups = groups;
mexpandableListDetail = expandableListDetail;
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getGroupCount() {
return mGroups.size();
}
#Override
public int getChildrenCount(int groupPosition) {
return mexpandableListDetail.get(mGroups.get(groupPosition)).size();
}
#Override
public Object getGroup(int groupPosition) {
return mGroups.get(groupPosition);
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return mexpandableListDetail.get(mGroups.get(groupPosition)).get(childPosition);
}
#Override
public long getGroupId(int groupPosition) {
return 0;
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.right_drawer_group, null);
}
// Get the group item
String listTitle = (String) getGroup(groupPosition);
// Set group name
TextView textView = (TextView) convertView.findViewById(R.id.textGroup);
textView.setText(listTitle);
ImageView indicator = (ImageView) convertView.findViewById(R.id.groupIndicator);
if (isExpanded) {
indicator.setImageResource(R.drawable.arrowup);
} else {
indicator.setImageResource(R.drawable.arrowdown);
}
return convertView;
}
#Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.right_drawer_child, null);
}
// Get child name
String children = (String) getChild(groupPosition, childPosition);
// Set child name
TextView text = (TextView) convertView.findViewById(R.id.textChild);
text.setText(children);
/*convertView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(mContext, children, Toast.LENGTH_SHORT).show();
}
});*/
return convertView;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
Please anyone help to me!
Thanks in advance
In your right_drawer_group.xml add an ImageView where you want your group image to be placed, lets say groupImage.
In your getGroupView:
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.right_drawer_group, null);
}
//Set group image
ImageView groupImage = (ImageView)convertView.findViewById(R.id.groupImage);
switch((String)getGroup(groupPosition))
{
case "As a Rider":
//groupImage set correct image
break;
case "As a Ridee":
//groupImage set correct image
break;
case "My Recent Activities":
//groupImage set correct image
break;
}
// Get the group item
String listTitle = (String) getGroup(groupPosition);
// Set group name
TextView textView = (TextView) convertView.findViewById(R.id.textGroup);
textView.setText(listTitle);
ImageView indicator = (ImageView) convertView.findViewById(R.id.groupIndicator);
if (isExpanded) {
indicator.setImageResource(R.drawable.arrowup);
} else {
indicator.setImageResource(R.drawable.arrowdown);
}
return convertView;
}
It's not the most neat solution as if you change the group name this will break, but it will work for now. Better solution would be is to pass the groups as objects containing getName and getImageId.

I have call another Activity when i click on child view of expandable listview in Android?

I want to call another activity when i click button which is child view of expandable listview in Android.When i run the activity does not show the expandable listview.How to work on exapandable list view.Can some one give me idea how to do this.
Here is my Activity code
public class My_Project extends ExpandableListActivity
{
ExpandableListView expListView;
Button btnNewProject;
Button btn_myprojectdefinemyteam;
DBHelper databaseHelper;
SQLiteDatabase db;
ImageView imgButtonBack;
List dispDataList;
String[] array;
String[] Task_Title_Size;
String[] Task_Start_Date_Size;
String[] Task_CompletionDate_Size;
String[] Task_CompletionTime_Size;
String[] Task_Description_Size;
String[] Task_Status_Size;
String[] Task_IsActive_Size;
String[] dtrProjectNAmeSize;
public static final String Task_Title = "Task_Titles";
public static final String Task_Start_Date = "start_date";
public static final String Task_CompletionDate = "completion_date";
public static final String Task_CompletionTime = "completion_time";
public static final String Task_Description = "task_description";
public static final String Task_Status = "task_status";
public static final String Task_IsActive ="IS_Active";
private int ParentClickStatus=-1;
private int ChildClickStatus=-1;
Myexpandable_ListAdapter mAdapter;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.my_project);
imgButtonBack = (ImageView)findViewById(R.id.imagBackButton);//ImageView imgButtonBack;
imgButtonBack.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent iBack = new Intent(My_Project.this , Menu.class);
startActivity(iBack);
finish();
}
});
expListView = (ExpandableListView) findViewById(android.R.id.list);
databaseHelper = new DBHelper(getApplicationContext());
dispDataList=databaseHelper.viewMyProjectDetals();
dtrProjectNAmeSize=new String[dispDataList.size()];
System.out.println(" dtrProjectNAmeSize = " + dtrProjectNAmeSize);
if ( dispDataList.size() > 6 )
{
Task_Title_Size=(String[])dispDataList.get(0);
Task_Start_Date_Size=(String[]) dispDataList.get(1);
Task_CompletionDate_Size = (String[])dispDataList.get(2);
Task_CompletionTime_Size=(String[])dispDataList.get(3);
Task_Description_Size=(String[]) dispDataList.get(4);
Task_Status_Size = (String[])dispDataList.get(5);
Task_IsActive_Size = (String[])dispDataList.get(6);
for(int i=0;i<Task_Title_Size.length;i++)
{
System.out.println("New data :"+Task_Title_Size[i]);
}
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
for (int i = 0; i < Task_Title_Size.length ; i++)
{
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(Task_Title,"" +Task_Title_Size[i]);
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(Task_Start_Date,"" +Task_Start_Date_Size[i]);
curChildMap.put(Task_CompletionDate,"" +Task_CompletionDate_Size[i]);
curChildMap.put(Task_CompletionTime,"" +Task_CompletionTime_Size[i]);
curChildMap.put(Task_Description,"" +Task_Description_Size[i]);
curChildMap.put(Task_Status,"" +Task_Status_Size[i]);
curChildMap.put(Task_IsActive,"" +Task_IsActive_Size[i]);
childData.add(children);
}
mAdapter =new Myexpandable_ListAdapter(
this,
groupData,
R.layout.list_group,
new String[] { Task_Title },
new int[] {R.id.lblListHeader },
childData,
R.layout.child_item,
new String[] { Task_Start_Date , Task_CompletionDate , Task_CompletionTime , Task_Description , Task_Status , Task_IsActive},
new int[] { R.id.TextView_Projectdetails , R.id.textOne , R.id.textTwo , R.id.textThree , R.id.textFour, R.id.textFive}
);
expListView.setAdapter(mAdapter);
}
expListView.setOnGroupClickListener(new OnGroupClickListener()
{
#Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id)
{
return false;
}
});
//editTextTaskName = (EditText)findViewById(R.id.Task_Name);
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
#Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(getApplicationContext(),
dtrProjectNAmeSize.length + " Expanded",
Toast.LENGTH_SHORT).show();
}
});
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getApplicationContext(),
dtrProjectNAmeSize.length + " Collapsed",
Toast.LENGTH_SHORT).show();
}
});
btnNewProject = (Button)findViewById(R.id.buttonmyproject_NewProject);
btnNewProject.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(My_Project.this , Add_Project.class);
startActivity(i);
finish();
}
});
}
private class Myexpandable_ListAdapter extends BaseExpandableListAdapter {
public Myexpandable_ListAdapter(Context context,
List<? extends Map<String, ?>> groupData,
int expandedGroupLayout,
String[] groupFrom, int[] groupTo,
List<? extends List<? extends Map<String, ?>>> childData,
int childLayout, String[] childFrom,
int[] childTo) {
super();
// TODO Auto-generated constructor stub
}
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
Context context;
public Object getChild(int groupPosition, int childPosition)
{
//this.get(groupPosition).getChildren().get(childPosition);
String strchildPosition = this._listDataChild.get(this._listDataHeader.get(groupPosition)).get(childPosition);
System.out.println("Child Position =" + strchildPosition);
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosition);
}
//Call when child row clicked
#Override
public long getChildId(int groupPosition, int childPosition)
{
/****** When Child row clicked then this function call *******/
//Log.i("Noise", "parent == "+groupPosition+"= child : =="+childPosition);
if( ChildClickStatus!=childPosition)
{
ChildClickStatus = childPosition;
Toast.makeText(getApplicationContext(), "Parent :"+groupPosition + " Child :"+childPosition ,
Toast.LENGTH_LONG).show();
}
return childPosition;
}
public View getChildView1(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
return parent;
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.child_item, null);
}
TextView txtListChild = (TextView) convertView.findViewById(R.id.TextView_Projectdetails);
TextView txtOneListChild = (TextView)convertView.findViewById(R.id.textOne);
TextView txtTwoListChild = (TextView)convertView.findViewById(R.id.textTwo);
TextView txtThreeListChild = (TextView)convertView.findViewById(R.id.textThree);
TextView txtFourListChild = (TextView)convertView.findViewById(R.id.textFour);
TextView txtFiveListChild = (TextView)convertView.findViewById(R.id.textFive);
txtListChild.setText(childText);
txtOneListChild.setText(childText);
txtTwoListChild.setText(childText);
txtThreeListChild.setText(childText);
txtFourListChild.setText(childText);
txtFiveListChild.setText(childText);
Button btnAssgnTask = (Button)convertView.findViewById(R.id.button_EditedTask);
btnAssgnTask.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
Button btnViewTask = (Button)convertView.findViewById(R.id.buttonViewTask);
btnViewTask.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
#Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
#Override
public int getGroupCount() {
return ParentClickStatus;
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
}
Thanks in Advance.
your problem is here:
#Override
public int getGroupCount() {
return ParentClickStatus;
}
as you extends BaseExpandableListAdapter, getChildrenCount and getGroupCount handle number of your view and as ParentClickStatus is equal to -1 getGroupView never called
solution
you need return group row number that you have, so change your code with:
#Override
public int getGroupCount() {
return _listDataHeader.size();
}
for an example you can see section 15. Implementing an expandable ListView
UPDATE
you need change your constructor too:
public Myexpandable_ListAdapter(Context context,
List<? extends Map<String, ?>> groupData,
int expandedGroupLayout,
String[] groupFrom, int[] groupTo,
List<? extends List<? extends Map<String, ?>>> childData,
int childLayout, String[] childFrom,
int[] childTo) {
super();
// TODO Auto-generated constructor stub
}
you passed your data to here, but you don't set to any local data, for example you tried to use _listDataChild in getChild method, but you not initialize that at all, you need initialize that in constructor with your data that passed here.

Categories