how to set the value at particular position in expandableListView - android

i have created a ExpandableListView.But There is a problem when i set the value of particular item same value set on all item i can not understand how to solve this.
this is my code.
direct_referal.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layoutfaq"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="25dp" >
<ExpandableListView
android:id="#+id/lvExp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:padding="10dp"
android:cacheColorHint="#00000000"/>
</LinearLayout>
This is My Main Xml File.
DirectReferal.java
public class DirectReferalFragment extends Fragment
{
ExpandableDirectReferalListAdapter listAdapter;
ExpandableListView expListView;
private List<String> userID;
private List<String> joiningDate;
private HashMap<String, List<String>> slNo;
private HashMap<String, List<String>> name;
private HashMap<String, List<String>> city;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.direct_referal, container, false);
// get the listview
expListView = (ExpandableListView) view.findViewById(R.id.lvExp);
expListView.setGroupIndicator(null);
// preparing list data
prepareListData();
listAdapter = new ExpandableDirectReferalListAdapter(this.getActivity(), userID, joiningDate, slNo, name, city);
// setting list adapter
expListView.setAdapter(listAdapter);
// Listview Group click listener
expListView.setOnGroupClickListener(new OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
return false;
}
});
// Listview Group expanded listener
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
#Override
public void onGroupExpand(int groupPosition) {
// TODO Auto-generated method stub
}
});
// Listview Group collasped listener
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int groupPosition) {
// TODO Auto-generated method stub
}
});
// Listview on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
return false;
}
});
return view;
}
/*
* Preparing the list data
*/
private void prepareListData() {
userID = new ArrayList<String>();
joiningDate = new ArrayList<String>();
slNo = new HashMap<String, List<String>>();
name = new HashMap<String, List<String>>();
city = new HashMap<String, List<String>>();
// Adding USER ID
userID.add("User ID : GLI000014");
userID.add("User ID : GLI000015");
userID.add("User ID : GLI000016");
userID.add("User ID : GLI000017");
userID.add("User ID : GLI000018");
// Adding JOINING DATE
joiningDate.add("Joining Date : 9 Nov,2015");
joiningDate.add("Joining Date : 9 Dec,2015");
joiningDate.add("Joining Date : 9 Jan,2016");
joiningDate.add("Joining Date : 9 Fab,2016");
joiningDate.add("Joining Date : 9 Mar,2016");
// Adding SL NO
List<String> no1 = new ArrayList<String>();
no1.add("SL No. : 1");
List<String> no2 = new ArrayList<String>();
no2.add("SL No. : 2");
List<String> no3 = new ArrayList<String>();
no3.add("SL No. : 3");
List<String> no4 = new ArrayList<String>();
no4.add("SL No. : 4");
List<String> no5 = new ArrayList<String>();
no5.add("SL No. : 5");
slNo.put(userID.get(0), no1); // Header, Child data
slNo.put(userID.get(1), no2);
slNo.put(userID.get(2), no3);
slNo.put(userID.get(3), no4);
slNo.put(userID.get(4), no5);
// Adding NAME
List<String> name1 = new ArrayList<String>();
name1.add("Name : Prabal Saxena");
List<String> name2 = new ArrayList<String>();
name2.add("Name : Chirag Mehta");
List<String> name3 = new ArrayList<String>();
name3.add("Name : Tarun Mehta");
List<String> name4 = new ArrayList<String>();
name4.add("Name : Prashant Gupta");
List<String> name5 = new ArrayList<String>();
name5.add("Name : Chotu");
name.put(userID.get(0), name1); // Header, Child data
name.put(userID.get(1), name2);
name.put(userID.get(2), name3);
name.put(userID.get(3), name4);
name.put(userID.get(4), name5);
// Adding CITY
List<String> city1 = new ArrayList<String>();
city1.add("City : Noida");
List<String> city2 = new ArrayList<String>();
city2.add("City : Gurgaun");
List<String> city3 = new ArrayList<String>();
city3.add("City : Delhi");
List<String> city4 = new ArrayList<String>();
city4.add("City : Pune");
List<String> city5 = new ArrayList<String>();
city5.add("SL No. : Delhi");
city.put(userID.get(0), city1); // Header, Child data
city.put(userID.get(1), city2);
city.put(userID.get(2), city3);
city.put(userID.get(3), city4);
city.put(userID.get(4), city5);
}
}
This is my main Java file. in this we set the value of all child and parent element and send the value via constructor.
list_item.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:background="#drawable/direct_referal_bg"
android:orientation="vertical" >
<TextView
android:id="#+id/lblListItemslno"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:gravity="left"
android:textColor="#000000" />
<TextView
android:id="#+id/lblListItemname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:gravity="left"
android:textColor="#000000" />
<TextView
android:id="#+id/lblListItemcity"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:gravity="left"
android:textColor="#000000" />
</LinearLayout>
list_group.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:background="#333333">
<TextView
android:id="#+id/lblListHeaderuserid"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="User ID : GLI000014"
android:textSize="12sp"
android:gravity="center"
android:textColor="#FFFFFF" />
<TextView
android:id="#+id/lblListHeaderjoindate"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Joining Date : 9 Nov, 2015"
android:textSize="12sp"
android:gravity="center"
android:textColor="#FFFFFF" />
</LinearLayout>
ExpandableDirectReferalListAdapter.java
public class ExpandableDirectReferalListAdapter extends BaseExpandableListAdapter {
private Context _context;
List<String> _userID;
List<String> _joiningDate;
HashMap<String, List<String>> _slNo;
HashMap<String, List<String>> _name;
HashMap<String, List<String>> _city;
public ExpandableDirectReferalListAdapter(Context context, List<String> userID,List<String> joiningDate,
HashMap<String, List<String>> slNo,HashMap<String, List<String>> name,
HashMap<String, List<String>> city) {
this._context = context;
this._userID = userID;
this._joiningDate = joiningDate;
this._slNo = slNo;
this._name = name;
this._city = city;
}
#Override
public Object getChild(int groupPosition, int childPosititon) {
return this._slNo.get(this._userID.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.list_item, null);
}
TextView txtListChildslno = (TextView) convertView.findViewById(R.id.lblListItemslno);
TextView txtListChildname = (TextView) convertView.findViewById(R.id.lblListItemname);
TextView txtListChildcity = (TextView) convertView.findViewById(R.id.lblListItemcity);
txtListChildslno.setText(childText);
txtListChildname.setText(childText);
txtListChildcity.setText(childText);
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return this._slNo.get(this._userID.get(groupPosition))
.size();
}
#Override
public Object getGroup(int groupPosition) {
return this._userID.get(groupPosition);
}
#Override
public int getGroupCount() {
return this._userID.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.list_group, null);
}
TextView lblListHeaderuserid = (TextView) convertView.findViewById(R.id.lblListHeaderuserid);
TextView lblListHeaderjoindate = (TextView) convertView.findViewById(R.id.lblListHeaderjoindate);
lblListHeaderuserid.setText(headerTitle);
lblListHeaderjoindate.setText(headerTitle);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
This is my Adapter class.in this we want to set diffrent value of all child and parent field but same value set on all field.
you can see the the output in this image..
enter image description here
How can i solve this problem, I can not understant.
please help.

Please correct getChildView method gand etGroupView method. The code will be as follows.
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
String slNo = _slNo.get(_userID.get(groupPosition)).get(0);
String childName = _name.get(_userID.get(groupPosition)).get(0);
String childCity = _city.get(_userID.get(groupPosition)).get(0);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChildslno = (TextView) convertView.findViewById(R.id.lblListItemslno);
TextView txtListChildname = (TextView) convertView.findViewById(R.id.lblListItemname);
TextView txtListChildcity = (TextView) convertView.findViewById(R.id.lblListItemcity);
txtListChildslno.setText(slNo);
txtListChildname.setText(childName);
txtListChildcity.setText(childCity);
return convertView;
}
#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 lblListHeaderuserid = (TextView) convertView.findViewById(R.id.lblListHeaderuserid);
TextView lblListHeaderjoindate = (TextView) convertView.findViewById(R.id.lblListHeaderjoindate);
lblListHeaderuserid.setText(headerTitle);
lblListHeaderjoindate.setText(_joiningDate.get(groupPosition));
return convertView;
}
Hope that you can understand what was your mistake..
I tested the code, it will work.

Related

Child view in Expandable list view get Shrinks automatically to wrap content, Even though I mentioned the View to match parent

EarBoxExpandableListAdapter
public class EarBoxExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public EarBoxExpandableListAdapter(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.childrow, null);
}
// TextView txtListChild = (TextView) convertView
// .findViewById(R.id.lblListItem);
//
// 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) {
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.parentrow, null);
}
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
Below is my xml layout code for the child row.Evwnthough I kept the width as match parent, in actual output which I attached as screen shot Im getting the wrap content of the child rows.
childrow.xml
<?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="wrap_content"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/btnPlay"
android:src="#android:drawable/ic_media_play"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/round_corner_rect"
android:layout_weight="0"
android:layout_margin="10dp" />
<TextView
android:id="#+id/songCurrentDurationLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="left"
android:textColor="#747272"
android:textStyle="bold"
android:visibility="visible"
android:text="3.25"
android:layout_gravity="center_vertical" />
<SeekBar
android:id="#+id/songProgressBar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:layout_weight="1"
android:layout_gravity="center" />
<TextView
android:id="#+id/songTotalDurationLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="right"
android:textColor="#656262"
android:textStyle="bold"
android:visibility="visible"
android:text="42:52"
android:layout_gravity="center_vertical" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<Button
style="#style/earBoxbuttonStyle"
android:text="Save"
android:id="#+id/button"
android:layout_weight="1"
android:layout_width="match_parent" />
<Button
style="#style/earBoxbuttonStyle"
android:text="Reply"
android:id="#+id/button3"
android:layout_weight="1"
android:layout_width="match_parent" />
<Button
style="#style/earBoxbuttonStyle"
android:text="Delete"
android:id="#+id/button4"
android:layout_weight="1"
android:layout_width="match_parent" />
</LinearLayout>
</LinearLayout>
MessageInboxFragment
/**
* Created by sethu on 6/13/2016.
*/
public class MessageInboxFragment extends Fragment{
ExpandableListView expandableListView;
EarBoxExpandableListAdapter listAdapter;
static List<String> listDataHeader;
static HashMap<String, List<String>> listDataChild;
private int lastExpandedPosition = -1;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_messages_inbox, container, false);
expandableListView=(ExpandableListView) rootView.findViewById(R.id.expandableListView);
expandableListView.setDividerHeight(1);
// final ArrayList<Parent> dummyList = ExpandableListMain.buildDummyData();
prepareListData();
listAdapter = new EarBoxExpandableListAdapter(getActivity(), listDataHeader, listDataChild);
expandableListView.setAdapter(listAdapter);
expandableListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
#Override
public void onGroupExpand(int groupPosition) {
if (lastExpandedPosition != -1
&& groupPosition != lastExpandedPosition) {
expandableListView.collapseGroup(lastExpandedPosition);
}
lastExpandedPosition = groupPosition;
}
});
return rootView;
}
public static void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
// Adding child data
listDataHeader.add("Top 250");
listDataHeader.add("Now Showing");
listDataHeader.add("Coming Soon..");
// Adding child data
List<String> top250 = new ArrayList<String>();
top250.add("The Shawshank Redemption");
List<String> nowShowing = new ArrayList<String>();
nowShowing.add("The Conjuring");
List<String> comingSoon = new ArrayList<String>();
comingSoon.add("2 Guns");
listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
listDataChild.put(listDataHeader.get(1), nowShowing);
listDataChild.put(listDataHeader.get(2), comingSoon);
}
}
xml screenshot
device output screenshot

Tabhost creating trouble in getChildlView method of ExpandableList

I have put tabs insilde a expandablelistview adapter and due to its getCHildView method tabs are generating multiple times in on parent click. How to resolve this .
This is an example of what I need to implement.
http://i.stack.imgur.com/rvPZe.png
In left side image there is list of expandable view to be shown to user. Once user click on any of the expandable view i need to display tabs inside childlistview of expandable list view as shown in right image.
Please see below the entire code
My Activity Class
public class CardList extends AppCompatActivity {
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_card_list);
// get the listview
expListView = (ExpandableListView) findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Toast.makeText(
getApplicationContext(),
listDataHeader.get(groupPosition)
+ " : "
+ listDataChild.get(
listDataHeader.get(groupPosition)).get(
childPosition), Toast.LENGTH_SHORT)
.show();
return false;
}
});
// Listview Group expanded listener
expListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
#Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Expanded",
Toast.LENGTH_SHORT).show();
}
});
expListView.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Collapsed",
Toast.LENGTH_SHORT).show();
}
});
}
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
listDataHeader.add("Top 250");
listDataHeader.add("Now Showing");
listDataHeader.add("Coming Soon..");
List<String> top250 = new ArrayList<String>();
top250.add("The Shawshank Redemption");
List<String> nowShowing = new ArrayList<String>();
nowShowing.add("The Conjuring");
List<String> comingSoon = new ArrayList<String>();
comingSoon.add("2 Guns");
listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
listDataChild.put(listDataHeader.get(1), nowShowing);
listDataChild.put(listDataHeader.get(2), comingSoon);
}
}
Activity xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#f4f4f4" >
<ExpandableListView
android:id="#+id/lvExp"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
</LinearLayout>
ExpandableListAdapter
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private Button b;
LinearLayout l;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
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(final 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.list_item, null);
}
final View views = convertView;
final ViewGroup parents =parent;
TabHost host = (TabHost)convertView.findViewById(R.id.tabHost);
host.setup();
TabHost.TabSpec spec = host.newTabSpec("Tab One");
spec.setContent(R.id.tab1);
spec.setIndicator("Tab One");
host.addTab(spec);
TabHost.TabSpec spec1 = host.newTabSpec("Tab Two");
spec1.setContent(R.id.tab2);
spec1.setIndicator("Tab Two");
host.addTab(spec1);
TabHost.TabSpec spec2 = host.newTabSpec("Tab Three");
spec2.setContent(R.id.tab3);
spec2.setIndicator("Tab Three");
host.addTab(spec2);
host.setFocusable(false);
host.setup();
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(final 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);
LinearLayout.LayoutParams firstParam = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 300);
//Random rnd = new Random();
int color = Color.argb(255, 104, 224, 201);
convertView = infalInflater.inflate(R.layout.list_group, null);
convertView.setLayoutParams(firstParam);
convertView.setBackgroundColor(color);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
ImageButton img = (ImageButton)convertView.findViewById(R.id.imageButton) ;
img.setFocusable(false);
System.out.println("headerTitle 123-------------------> "+headerTitle);
img.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("headerTitle -------------------> "+(String) getGroup(groupPosition));
Intent i = new Intent(_context,DashboardActivity.class);
i.putExtra("feroz",(String) getGroup(groupPosition));
_context.startActivity(i);
}
});
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;
}
private Button addTextView(){
Button Button = new Button(_context);
Button.setText("submit");
return Button;
}
}
list_group.xml for parent view
<?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="100dp"
android:orientation="horizontal"
android:padding="8dp"
android:background="#000000"
android:weightSum="100"
> <TextView
android:id="#+id/lblListHeader"
android:layout_width="0dp"
android:layout_height="match_parent"
android:textSize="17dp"
android:text="hello "
android:textColor="#fff"
android:layout_weight="60"
/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/imageView"
android:src="#drawable/line"
android:layout_weight="10"/>
<ImageButton
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/imageButton"
android:layout_weight="30"
android:src="#drawable/launch"
android:background="#00000000"
android:clickable="true" />
</LinearLayout>
list_item for child view
<?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="100dip"
android:orientation="horizontal"
android:weightSum="100">
<TabHost
android:id="#+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffc916"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="This is tab 1" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#da8200"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="This is tab 2" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#5b89ff"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="This is tab 3" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
After doing little amount of research I got to know that the problem is with convert view which you are reusing for the child once it gets created once. But not for the TabHost. You are creating the TabHost every time even if the view is already gets created and also tabhost setup is also done for the same child.I have just edited adapter class and for research one method prepareListData(). SO here is the edited code:-
MyExpandableListAdapter.java
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private Button b;
LinearLayout l;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public MyExpandableListAdapter(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(final 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.list_child, null);
TabHost host = (TabHost) convertView.findViewById(R.id.tabHost);
host.setup();
Log.e("tab count",""+host.getTabWidget().getTabCount());
TabHost.TabSpec spec = host.newTabSpec("Tab One");
spec.setContent(R.id.tab1);
spec.setIndicator("Tab One");
host.addTab(spec);
TabHost.TabSpec spec1 = host.newTabSpec("Tab Two");
spec1.setContent(R.id.tab2);
spec1.setIndicator("Tab Two");
host.addTab(spec1);
TabHost.TabSpec spec2 = host.newTabSpec("Tab Three");
spec2.setContent(R.id.tab3);
spec2.setIndicator("Tab Three");
host.addTab(spec2);
host.setFocusable(false);
host.setup();
}
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(final 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);
LinearLayout.LayoutParams firstParam = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 300);
//Random rnd = new Random();
int color = Color.argb(255, 104, 224, 201);
convertView = infalInflater.inflate(R.layout.list_group, null);
convertView.setLayoutParams(firstParam);
convertView.setBackgroundColor(color);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
ImageButton img = (ImageButton)convertView.findViewById(R.id.imageButton) ;
img.setFocusable(false);
System.out.println("headerTitle 123-------------------> "+headerTitle);
img.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("headerTitle -------------------> "+(String) getGroup(groupPosition));
Intent i = new Intent(_context,DashboardActivity.class);
i.putExtra("feroz",(String) getGroup(groupPosition));
_context.startActivity(i);
}
});
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;
}
private Button addTextView(){
Button Button = new Button(_context);
Button.setText("submit");
return Button;
}
}
prepareListData() method
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
listDataHeader.add("Top 250");
listDataHeader.add("Now Showing");
listDataHeader.add("Coming Soon..");
listDataHeader.add("Item 4..");
listDataHeader.add("Item 5..");
List<String> top250 = new ArrayList<String>();
top250.add("The Shawshank Redemption");
List<String> nowShowing = new ArrayList<String>();
nowShowing.add("The Conjuring");
List<String> comingSoon = new ArrayList<String>();
comingSoon.add("2 Guns");
listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
listDataChild.put(listDataHeader.get(1), nowShowing);
listDataChild.put(listDataHeader.get(2), comingSoon);
listDataChild.put(listDataHeader.get(3), new ArrayList<String>());
listDataChild.put(listDataHeader.get(4), comingSoon);
}

ExpandableListView is not expanding

I m creating ExpandableList view in Fragment, the Group item display in list, but when I touch the group item, it is not expanding.
Below is my fragment
public class InstituteFragment extends Fragment {
ExpandableListView expandableListView;
ArrayList<String> subjectName;
HashMap<String,ArrayList<String>> topicName;
public InstituteFragment() {
}
public static InstituteFragment newInstance(){
InstituteFragment fragment = new InstituteFragment();
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
subjectName = new ArrayList<>();
topicName = new HashMap<>();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_institute, container, false);
prepData();
expandableListView = (ExpandableListView)view.findViewById(R.id.expd_list_view);
SubjectAdapter adapter = new SubjectAdapter(getActivity(),subjectName,topicName);
expandableListView.setAdapter(adapter);
return view;
}
private void prepData() {
subjectName.add("Physics");
subjectName.add("Chemistry");
subjectName.add("Biology");
ArrayList<String> physics = new ArrayList<>();
physics.add("Demo");
physics.add("Demo1");
physics.add("Demo2");
physics.add("Demo3");
ArrayList<String> chemistry = new ArrayList<>();
chemistry.add("Demo");
chemistry.add("Demo1");
chemistry.add("Demo2");
chemistry.add("Demo3");
ArrayList<String> biology = new ArrayList<>();
biology.add("Demo");
biology.add("Demo1");
biology.add("Demo2");
biology.add("Demo3");
topicName.put(subjectName.get(0), physics);
topicName.put(subjectName.get(1),chemistry);
topicName.put(subjectName.get(2),biology);
}
}
below is adapter
public class SubjectAdapter extends BaseExpandableListAdapter {
Context context;
ArrayList<String> subjectName;
HashMap<String,ArrayList<String>> topicName;
public SubjectAdapter(Context context, ArrayList<String> subjectName, HashMap<String, ArrayList<String>> topicName) {
this.context = context;
this.topicName = topicName;
this.subjectName = subjectName;
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return this.topicName.get(this.subjectName.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) {
final String childText = (String) getChild(groupPosition, childPosition);
LayoutInflater infalInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.chapter_name, null);
TextView txtListChild = (TextView) convertView
.findViewById(R.id.chapter_name);
txtListChild.setText(childText);
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return this.topicName.get(this.subjectName.get(groupPosition)).size();
}
#Override
public int getGroupCount() {
return this.subjectName.size();
}
#Override
public Object getGroup(int groupPosition) {
return this.subjectName.get(groupPosition);
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String subjectName = (String)getGroup(groupPosition);
LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.subject_name,null);
TextView textView = (TextView)convertView.findViewById(R.id.subject_name);
textView.setText(subjectName);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
below is institute_fragment.xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragment.InstituteFragment">
<ExpandableListView
android:id="#+id/expd_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ExpandableListView>
</RelativeLayout>
below is my groupview
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/_10sdp"
android:layout_margin="#dimen/_5sdp"
android:background="#android:color/white"
android:id="#+id/subject_name_cardview">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/subject_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject Name"
android:textAppearance="?android:textAppearanceMedium"
android:padding="#dimen/_10sdp"
android:layout_marginTop="#dimen/_10sdp"
android:layout_marginBottom="#dimen/_10sdp"
android:layout_marginLeft="#dimen/_10sdp"
android:textColor="#android:color/black" />
<ImageButton
android:id="#+id/subject_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_keyboard_arrow_down_24dp"
android:background="#00000000"
android:layout_marginRight="#dimen/_20sdp"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
below is childView xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_5sdp"
android:background="#color/colorPrimary"
android:id="#+id/chapter_name_cardview">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/chapter_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject Name"
android:textAppearance="?android:textAppearanceSmall"
android:padding="#dimen/_10sdp"
android:layout_marginTop="#dimen/_5sdp"
android:layout_marginBottom="#dimen/_5sdp"
android:layout_marginLeft="#dimen/_10sdp"
android:textColor="#android:color/black" />
<ImageButton
android:id="#+id/chapter_name_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_keyboard_arrow_right_24dp"
android:background="#00000000"
android:layout_marginRight="#dimen/_20sdp"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
Well, easy one.
You have imagebutton in groupview that is intercepting touch event. Add these parameters:
android:focusable="false"
android:focusableInTouchMode="false"
And do same for childview. You have exactly the same case there.
P.S. why are you using imagebuttons anyway? you could use imageviews instead
You need to do this one.
expandableListView = (ExpandableListView)view.findViewById(R.id.expd_list_view);
SubjectAdapter adapter = new SubjectAdapter(getActivity(),subjectName,topicName);
expandableListView.setAdapter(adapter);
expandableListView .setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView expandableListView, View view, int groupPosition, long l) {
expandableListView.expandGroup(groupPosition);
return false;
}
});
Hope this will help you.
Try to pass your ExpandableListView in the adapter:
SubjectAdapter adapter = new SubjectAdapter(getActivity(),subjectName,topicName, expandableListView);
Then youe adapter should look like:
...
ExpandableListView expandableListView;
public SubjectAdapter(Context context, ArrayList<String> subjectName, HashMap<String, ArrayList<String>> topicName, ExpandableListView expandableListView) {
this.context = context;
this.topicName = topicName;
this.subjectName = subjectName;
this.expandableListView = expandableListView;
}
In your group view add following:
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
expandableListView.expandGroup(groupPosition);
}
});

OnChildClickListener not working in expandable listview

I have no idea what's wrong with this code my onChildClickListener() is not called I have seen some answers in which they said override isChildSelected and return true; i tried that too but still it's not getting called. Can anybody help me in this. Any help would be appreciated. Thanks.
public class Expand {
Context context;
private RelativeLayout relativeLayout;
private String[] headerText;
String[] secondHeaderTitle;
int[] secondHeaderVisibilty;
String[][] drdatewise;
String[][] spec;
ExpandableListView listView;
ExampleAdapter adapter;
public TextView secondHeader;
public Expand(Context context, String headerText[],
String[] secondHeaderTitle, int[] secondHeaderVisibilty,
String[][] drdatewise, String[][] spec) {
this.context = context;
this.headerText = headerText;
this.secondHeaderTitle = secondHeaderTitle;
this.secondHeaderVisibilty = secondHeaderVisibilty;
secondHeader = new TextView(context);
this.drdatewise = drdatewise;
this.spec = spec;
}
public View GetView() {
List<GroupItem> items = new ArrayList<GroupItem>();
// Populate our list with groups and it's children
for (int i = 0; i < headerText.length; i++) {
GroupItem item = new GroupItem();
item.title = headerText[i];
for (int j = 0; j < drdatewise[i].length; j++) {
ChildItem child = new ChildItem();
child.title1String = drdatewise[i][j];
child.title2String = spec[i][j];
child.title3String = "Class A";
child.title4String = "Mumbai";
item.items.add(child);
}
items.add(item);
}
adapter = new ExampleAdapter(context);
adapter.setData(items);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
relativeLayout = (RelativeLayout) inflater.inflate(
R.layout.activity_main_gb, null);
listView = (ExpandableListView) relativeLayout
.findViewById(R.id.listView);
listView.setAdapter(adapter);
listView.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
Toast.makeText(context, "Mine mine minemie n", Toast.LENGTH_SHORT).show();
return true;
}
});
return relativeLayout;
}
private class ExampleAdapter extends BaseExpandableListAdapter {
private LayoutInflater inflater;
private List<GroupItem> items;
View convertView;
public ExampleAdapter(Context context) {
inflater = LayoutInflater.from(context);
}
public void setData(List<GroupItem> items) {
this.items = items;
}
#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 getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
ChildHolder holder;
ChildItem item = getChild(groupPosition, childPosition);
this.convertView = convertView;
if (convertView == null) {
holder = new ChildHolder();
convertView = inflater.inflate(R.layout.child_view_cal, parent,
false);
holder.title1 = (TextView) convertView
.findViewById(R.id.childtextview1);
holder.title2 = (TextView) convertView
.findViewById(R.id.childtextview2);
holder.title3 = (TextView) convertView
.findViewById(R.id.childtextview3);
holder.title4 = (TextView) convertView
.findViewById(R.id.childtextview4);
convertView.setTag(holder);
} else {
holder = (ChildHolder) convertView.getTag();
}
holder.title1.setText(item.title1String);
holder.title2.setText(item.title2String);
holder.title3.setText(item.title3String);
holder.title4.setText(item.title4String);
return convertView;
}
#Override
public int getChildrenCount(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.parent_view_cal,
parent, false);
holder.title = (TextView) convertView
.findViewById(R.id.headertextview);
holder.patches = (TextView) convertView
.findViewById(R.id.headertextview2223);
holder.count = (TextView) convertView
.findViewById(R.id.headertextview223);
convertView.setTag(holder);
} else {
holder = (GroupHolder) convertView.getTag();
}
holder.title.setText(item.title);
int countD = getChildrenCount(groupPosition);
holder.count.setText("" + countD);
holder.patches.setText("1");
return convertView;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public boolean isChildSelectable(int arg0, int arg1) {
return true;
}
}
private static class GroupHolder {
TextView title;
TextView patches;
TextView count;
}
private static class GroupItem {
String title;
String secondHeaderTitle;
List<ChildItem> items = new ArrayList<ChildItem>();
}
private static class ChildItem {
String title1String;
String title2String;
String title3String;
String title4String;
}
private static class ChildHolder {
TextView title1;
TextView title2;
TextView title3;
TextView title4;
}
}
child view
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/upperlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#E3ECF5"
android:gravity="center_vertical"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingTop="13dp" >
<ImageView
android:id="#+id/childImage"
android:layout_width="58dp"
android:layout_height="58dp"
android:layout_gravity="left"
android:src="#drawable/ic_account_box_black_48dp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:gravity="left"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:id="#+id/childtextview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Data1"
android:textColor="#424242"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/childtextview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Data2"
android:textColor="#424242"
android:textSize="16sp"
android:textStyle="normal" />
<TextView
android:id="#+id/childtextview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Data3"
android:textColor="#424242"
android:textSize="14sp"
android:textStyle="normal" />
<TextView
android:id="#+id/childtextview4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Data4"
android:textColor="#424242"
android:textSize="14sp"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingTop="13dp" >
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:text="11:00" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_below="#+id/upperlayout"
android:background="#FFFFFF" />
</RelativeLayout>
It is possible that your ImageView and possibly TextViews in the child layout are intercepting the click events. In your XML, try adding android:focusable="false" to all those elements.

Expandable ListView display child group view instead of group view

I implement an ExpandableList in my app.
when i finish it work totally wrong.
List have only one row and in it display child data in row title view,
Here is my code :
My list adpater :
public class JoinUsAdapter extends BaseExpandableListAdapter {
public static final String DESCRIPTION_TG = "description";
public static final String TITLE_TG = "title";
private Context mContext;
private List<Map<String, String>> mData;
private LayoutInflater inflater;
private ViewHolder vholder;
public JoinUsAdapter(Context context, List<Map<String, String>> data) {
this.mContext = context;
this.mData = data;
inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getGroupCount() {
return mData.size();
}
#Override
public int getChildrenCount(int groupPosition) {
return 1;
}
#Override
public Map<String , String> getGroup(int groupPosition) {
return mData.get(groupPosition);
}
#Override
public String getChild(int groupPosition, int childPosition) {
return mData.get(groupPosition).get(DESCRIPTION_TG);
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return 1;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.row_title_join_us, null);
vholder = new ViewHolder();
vholder.txtTitle = (TextView) convertView.findViewById(R.id.txtNewsTitle);
vholder.txtShortDesc = (TextView) convertView.findViewById(R.id.txtNewsShortDesc);
convertView.setTag(vholder);
}
else {
vholder = (ViewHolder) convertView.getTag();
}
Map item = getGroup(groupPosition);
vholder.txtTitle.setText(item.get(TITLE_TG).toString());
vholder.txtTitle.setText(truncate(item.get(DESCRIPTION_TG).toString(),35)+" ...");
return convertView;
}
#Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.row_detail_join_us, null);
}
TextView txtLongDesc =(TextView) convertView.findViewById(R.id.txtLongDescription);
txtLongDesc.setText(getChild(groupPosition,childPosition));
return convertView;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
And here is my Layouts :
title(as list row view) :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtNewsTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TITLE"
android:textStyle="bold"
android:textColor="#color/white"/>
<TextView
android:id="#+id/txtNewsShortDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="news description news description news description news description"
android:textStyle="bold"
android:textColor="#color/white"/>
</LinearLayout>
Detail: (as child of rows)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txtLongDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="#color/white"
android:text="long description long description long description long description long description long description "/>
</LinearLayout>
I cant find where is my mistake :/
Update:
My method for create fake data :
public void getData() {
dataList = new ArrayList<Map<String, String>>();
Map<String, String> item = new HashMap<String, String>();
String fake = "We asked respondents how satisfied they are with their current job or jobs. 76% of developers report being at least satisfied with their job, and 36% love their job. Developers are generally more fulfilled by work than most employees.\n" +
"\n" +
"And developers in Iran are more satisfied with their jobs than developers anywhere else. Stack Overflow Careers may not have any jobs available in Iran, but you can still move there and apply for one of our many available remote jobs.";
for(int i=0; i<10; i++) {
item.put(JoinUsAdapter.TITLE_TG,"Title "+i);
item.put(JoinUsAdapter.DESCRIPTION_TG,fake);
dataList.add(item);
}

Categories

Resources