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);
}
});
Related
What I want to implement is putting a GridView in the Expandable List.
Currently, my code has two adapters called "CustomListAdapter" that connects the GridView to the Expandable List and "SiteAdapter" which connects the data to the GridView.
The code that we have built so far is well connected to the Expandable List to the GridView. However, the data inside the gridView seems to be connected to the gridView (seeing the items in the gridview and clicking on the appropriate link), but the image and text that make up the gridview's internal design do not appear on the screen.
I have used setImage and setText inside the adapter code called "siteAdapter", but I do not know why it is not configured properly on the screen.
1] SiteAdapter.java (the siteAdapter code that links the GridView and the items)
public class SiteAdapter extends ArrayAdapter<Site> {
private Site currentSite;
public SiteAdapter(Context context, ArrayList<Site> sites) {
super(context, 0, sites);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View listItemView = convertView;
if(listItemView == null){
listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item,parent,false);
}
currentSite = getItem(position);
ImageView imageView = (ImageView) listItemView.findViewById(R.id.image);
imageView.setBackground(new ShapeDrawable(new OvalShape()));
imageView.setClipToOutline(true);
imageView.setImageBitmap(bitmap);
TextView name = (TextView) listItemView.findViewById(R.id.name);
name.setText(currentSite.getMsite_name());
return listItemView;
}
2] CustomListAdapter.java (links the ExpandableList and the GridView)
public class CustomListAdapter extends BaseExpandableListAdapter {
private Context mContext;
private ArrayList<String> arrayGroup;
private HashMap<String,ArrayList<Site>> arrayChild;
public CustomListAdapter(Context context, ArrayList<String> arrayGroup, HashMap<String, ArrayList<Site>> arrayChild){
super();
this.mContext = context;
this.arrayGroup = arrayGroup;
this.arrayChild = arrayChild;
}
#Override
public int getGroupCount() {
return arrayGroup.size();
}
#Override
public int getChildrenCount(int groupPosition) {
return arrayChild.get(arrayGroup.get(groupPosition)).size();
}
#Override
public Object getGroup(int groupPosition) {
return arrayGroup.get(groupPosition);
}
#Override
public Object getChild(int groupPosition, int childPosition)
{
return arrayChild.get(arrayGroup.get(groupPosition)).get(childPosition);
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public long getChildId(int groupPosition, int childPosition){
return childPosition;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String groupName = arrayGroup.get(groupPosition);
View v = convertView;
if(v==null){
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = (LinearLayout)inflater.inflate(R.layout.parent_listview_title, null);
}
TextView textGroup = (TextView) v.findViewById(R.id.title_site_list);
textGroup.setText(groupName);
return v;
}
#Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent){
String groupName = arrayGroup.get(groupPosition);
View v = convertView;
if(v == null){
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = (LinearLayout)inflater.inflate(R.layout.child_gridview_item, null);
}
SiteAdapter siteAdapter = new SiteAdapter(mContext,arrayChild.get(groupName));
GridView gridView = (GridView) v.findViewById(R.id.gridView);
gridView.setAdapter(siteAdapter);
return v;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
3] site_list.xml
<LinearLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<ExpandableListView
android:id="#+id/parentList"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ExpandableListView>
</LinearLayout>
4] parent_listview_title.xml(Code that designed the parent list of the Expandable List)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/title_site_list"
android:layout_width="wrap_content"
android:textSize="40sp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:textColor="#000000"
android:layout_marginLeft="16dp"
android:fontFamily="#font/bm_dohyeon"
android:textStyle="bold"/>
</LinearLayout>
5] child_gridview_item.xml(Code that designed the child list of the Expandable List)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<ViewSwitcher
android:id="#+id/visibility"
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_marginTop="20dp">
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#FFFFFF"
/>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#FFFFFF"
tools:context=".home"
android:id="#+id/gridView"
android:columnWidth="96dp"
android:numColumns="4"
android:verticalSpacing="10dp"
android:horizontalSpacing="4dp"
android:stretchMode="columnWidth"
android:gravity="center"/>
</ViewSwitcher>
</LinearLayout>
6] list_item.xml(The code that designs the contents of the gridview, the child list of the Expandable List)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
>
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="#+id/image"
android:scaleType="centerCrop"
tools:src="#mipmap/ic_launcher"
android:layout_gravity="center"
/>
<TextView
android:layout_width="60dp"
android:layout_height="wrap_content"
android:id="#+id/name"
tools:text="Gistsite"
android:textAppearance="?android:textAppearanceMedium"
android:textStyle="bold"
android:gravity="center_horizontal"
android:textSize="4sp"
/>
</LinearLayout>
7] Site.java
public class Site {
private String msite_name;
private String msite_url;
private String msite_urlF;
private String msite_urlY;
private String msite_urlB;
private String msite_urlW;
private String msite_urlI;
private int msite_imagesource;
public Site(String name, String url, int imagesource){
msite_name = name;
msite_url = url;
msite_imagesource = imagesource;
}
public Site(String name, String urlf, String urly, int imagesource){
msite_name = name;
msite_urlF = urlf;
msite_urlY = urly;
msite_imagesource = imagesource;
}
public Site(String name, String urlw, String urlb, String urlf, String urli,int imagesource){
msite_name = name;
msite_urlW = urlw;
msite_urlB = urlb;
msite_urlF = urlf;
msite_urlI = urli;
msite_imagesource = imagesource;
}
public String getMsite_name() {
return this.msite_name;
}
public String getMsite_url(){
return this.msite_url;
}
public String getMsite_urlW(){
return this.msite_urlW;
}
public String getMsite_urlB(){ return this.msite_urlB; }
public String getMsite_urlF(){
return this.msite_urlF;
}
public String getMsite_urlY(){
return this.msite_urlY;
}
public String getMsite_urlI(){
return this.msite_urlI;
}
public int getMsite_imagesource(){
return this.msite_imagesource;
}
In summary, the problem is that the contents of the image view and text view designed in list_item.xml are not available.
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.
I have a custom ExpandableList.
list_group.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="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="#drawable/rounded_corner_layout">
<TextView
android:id="#+id/lblListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:textSize="17dp"
android:textColor="#ffffff" />
</LinearLayout>
list_item.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="65dip"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="315dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="0dp"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="290dp"
android:layout_height="50dp"
android:layout_marginLeft="12dp"
android:src="#drawable/buton" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageView1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/lblListItem"
android:layout_width="189dp"
android:layout_height="30dp"
android:layout_marginBottom="-5dp"
android:layout_marginLeft="10dp"
android:paddingTop="5dp"
android:textColor="#000000"
android:textSize="17dip" />
</LinearLayout>
</RelativeLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:layout_marginLeft="10dp"
android:text="#string/descripcion"
android:textColor="#color/d_gray" />
</LinearLayout>
</RelativeLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignLeft="#+id/imageView2"
android:layout_centerVertical="true"
android:src="#drawable/pixel" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
ListAdapter.java
public class ExpandableListAdapter 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 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.list_item, 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.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;
}
}
itm.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
>
<ImageView
android:id="#+id/icon"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/title_item"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="#id/icon"
android:textColor="#FAFAFA"
android:gravity="center_vertical"
android:paddingRight="40dp"
android:paddingTop="15dp"
android:paddingBottom="15dp"/>
</RelativeLayout>
MainActivity.java
public class MainActivity extends Fragment {
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//.....
ListView listView =
(ListView) root.findViewById(R.id.myListView);
//......
// get the listview
expListView = (ExpandableListView) root.findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader,
listDataChild);
// 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) {
// Toast.makeText(getApplicationContext(),
// "Group Clicked " + listDataHeader.get(groupPosition),
// Toast.LENGTH_SHORT).show();
return false;
}
});
// Listview Group expanded listener
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
#Override
public void onGroupExpand(int groupPosition) {
/*
Toast.makeText(getActivity().getApplicationContext(),
listDataHeader.get(groupPosition) + " Expanded",
Toast.LENGTH_SHORT).show();
*/
}
});
// Listview Group collasped listener
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int groupPosition) {
/*
Toast.makeText(getActivity().getApplicationContext(),
listDataHeader.get(groupPosition) + " Collapsed",
Toast.LENGTH_SHORT).show();
*/
}
});
// Listview on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// toast
/*Toast.makeText( getActivity().getApplicationContext(),
listDataHeader.get(groupPosition) + " : " +
listDataChild.get( listDataHeader.get(groupPosition)).get(childPosition), Toast.LENGTH_SHORT).show();*/
// fin toast
return false;
}
});
return root;
}
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
// Adding child data
listDataHeader.add("Group1");
listDataHeader.add("Group2");
listDataHeader.add("Group3");
// Adding child data
List<String> G1 = new ArrayList<String>();
G1.add("Café con leche.... 1.20€");
G1.add("Manchado.... 1.20€");
G1.add("Cortado.... 1.20€");
List<String> G2 = new ArrayList<String>();
G2.add("item 1 Group 2");
G2.add("item 2 Group 2");
G2.add("item 3 Group 2");
List<String> G3 = new ArrayList<String>();
G3.add("item 1 Group 3");
G3.add("item 2 Group 3");
G3.add("item 3 Group 3");
listDataChild.put(listDataHeader.get(0), G1); // Header, Child data
listDataChild.put(listDataHeader.get(1), G2);
listDataChild.put(listDataHeader.get(2), G3);
}
}
okay, that it works perfect.
My problem!!
I need two TextView on Child items, I can't implement the second Textview, I don't know how I can add the second TextView on Adapter and later populate manually with a String.
I need do that.
Group item:
<?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="wrap_content"
android:orientation="horizontal"
android:padding="8dp"
android:background="#drawable/rounded_corner_layout">
<TextView
android:id="#+id/lblListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:textSize="17dp"
android:textColor="#ffffff" />
<TextView
android:id="#+id/tv2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:textSize="17dp"
android:textColor="#ffffff" />
</LinearLayout>
Notice that you should change layout orientation to horizontal!
Adapter:
#Override
public View getGroupView(int groupPosition, boolean isLastChild, View view,
ViewGroup parent) {
LayoutInflater inf = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (view == null) {
view = inf.inflate(R.layout.list_group, null);
}
TextView heading = (TextView) view.findViewById(R.id.lblListHeader);
TextView textView2 = (TextView) view.findViewById(R.id.tv2);
return view;
}
Here you can set text of both text views and set click listeners
In code:
lista.setAdapter(listAdapter);
listAdapter.notifyDataSetChanged();
You can create 2 objects (group and child) and use it in adapter.
public class Child{
String field1;
String field2;
}
public class Group{
String groupName;
ArrayList<Child> children;
}
public class Adapter extensextends BaseExpandableListAdapter {
ArrayList<Group> groups;
...
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
...
groupName = groups.get(groupPosition).getGroupName();
...
return convertView;
}
...
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
...
chieldField = groups.get(groupPosition).getChildren().get(childPosition).getField();
...
return convertView;
}
...
My problem is, that I have an activity with one big TextView and one ExpandableListView underneath the TextView. Unfortunately the text of the TextView is too long, so I can't see the details when I expand the ExpandableListView.
So my question is, how can I use CWAC-Merge in my Code, to get one big scrollable Activity.
I would like to have, that everything in the activity_contact.xml from scrollView1 to the bottom is scrollable! I already copied the necessary libs (merge-1.0.1.jar and sacklist-1.0.0.jar) to my Project, but I don't know how to apply the MergeAdapter. I would really appreciate, if someone could tell me where and how I have to use the MergeAdapter!
This is my activity_contact.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/titlebar" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_marginTop="0dp"
android:layout_weight="1"
android:fillViewport="true" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="#string/contact"
android:textSize="#dimen/textSize" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ExpandableListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
</ExpandableListView>
</TableRow>
</TableLayout>
</ScrollView>
</LinearLayout>
This is my Contact.java class:
public class Contact extends Activity {
private SparseArray<Group> groups = new SparseArray<Group>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contact);
ExpandableListView listView = (ExpandableListView) findViewById(R.id.listView);
createData();
ExpandableListAdapter adapter = new ExpandableListAdapter(this, groups,
false, null);
listView.setAdapter(adapter);
}
private void createData() {
Group group1 = new Group(getString(R.string.stringGroup));
group1.children.add(getString(R.string.stringGroup2));
groups.append(0, group1);
}
}
This is my ExpandableListAdapter.java
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private final SparseArray<Group> groups;
private LayoutInflater inflater;
private Activity activity;
private boolean setOnClickListener;
private Class<?> onClickClass;
public ExpandableListAdapter(Activity act, SparseArray<Group> groups,
boolean setOnClickListener, Class<?> onClickListenerClass) {
activity = act;
this.groups = groups;
inflater = act.getLayoutInflater();
this.setOnClickListener = setOnClickListener;
this.onClickClass = onClickListenerClass;
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return groups.get(groupPosition).children.get(childPosition);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String children = (String) getChild(groupPosition, childPosition);
TextView text = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.listrow_details, null);
}
text = (TextView) convertView.findViewById(R.id.copyrightTextView);
text.setText(Html.fromHtml(children));
if (setOnClickListener) {
convertView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(activity, onClickClass);
intent.putExtra("name", children);
activity.startActivity(intent);
}
});
}
return convertView;
}
#Override
public int getChildrenCount(int groupPosition) {
return groups.get(groupPosition).children.size();
}
#Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
#Override
public int getGroupCount() {
return groups.size();
}
#Override
public void onGroupCollapsed(int groupPosition) {
super.onGroupCollapsed(groupPosition);
}
#Override
public void onGroupExpanded(int groupPosition) {
super.onGroupExpanded(groupPosition);
}
#Override
public long getGroupId(int groupPosition) {
return 0;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.listrow_group, null);
}
Group group = (Group) getGroup(groupPosition);
((CheckedTextView) convertView).setText(group.string);
((CheckedTextView) convertView).setChecked(isExpanded);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
}
The listrow_details.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="50dp"
android:clickable="true"
android:orientation="vertical" >
<TextView
android:id="#+id/copyrightTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="15dp"
android:gravity="center_vertical"
android:linksClickable="true"
android:padding="10dp"
android:textStyle="bold" >
</TextView>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/black" />
</LinearLayout>
MergeAdapter is a ListAdapter, not an ExpandableListAdapter. You cannot use MergeAdapter to solve your problem. You are welcome to read through the source code to MergeAdapter and attempt to figure out if there is a way to create a MergeExpandableListAdapter or something like that.
Or, come up with a UI that does not have a long TextView after the ExpandableListView.
I need to use Android ExpandableListView with custom layout for each group(groups have one child). To accomplish this, I've created a class which extends BaseExpandableListAdapter. On the getChildView method, I've created the view of each child. It works. When I click a group, its child comes with true layout. However, during the debuging, I see that it triggers getchildview method many times, so it is too slow to display child. Because there are a lot of operations on each child (db operations, dynamic sub layouts...).
There are a small project, which similar to my project(Logic and code structure are same, only layout code and code of creating each child view are different).
public class MainActivity extends Activity {
private ArrayList<String> groups;
private ArrayList<ArrayList<ArrayList<String>>> childs;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExpandableListView l = (ExpandableListView)findViewById(R.id.expandableListView1);
loadData();
final myExpandableAdapter adapter = new myExpandableAdapter(this, groups, childs);
l.setAdapter(adapter);
}
public class myExpandableAdapter extends BaseExpandableListAdapter {
private ArrayList<String> groups;
private ArrayList<ArrayList<ArrayList<String>>> children;
private Context context;
public myExpandableAdapter(Context context, ArrayList<String> groups, ArrayList<ArrayList<ArrayList<String>>> children) {
this.context = context;
this.groups = groups;
this.children = childs;
}
#Override
public boolean areAllItemsEnabled()
{
return true;
}
public ArrayList<String> getChild(int groupPosition, int childPosition) {
return children.get(groupPosition).get(childPosition);
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,View convertView, ViewGroup parent) {
String child=(String)getChild(groupPosition, childPosition).get(0);
switch (groupPosition){
case 0:
LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.child_row, null);
TextView tvPlayerName = (TextView) convertView.findViewById(R.id.tvPlayerName);
tvPlayerName.setText(child);
break;
case 1:
LayoutInflater inflater1 = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater1.inflate(R.layout.child_row1, null);
TextView tvPlayerName1 = (TextView) convertView.findViewById(R.id.tvPlayerName);
tvPlayerName1.setText(child);
Button btn=(Button)convertView.findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
TextView tv=(TextView)findViewById(R.id.tv);
tv.setText("Clicked");
}
});
break;
case 2:
LayoutInflater inflater2 = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater2.inflate(R.layout.child_row1, null);
TextView tvPlayerName12 = (TextView) convertView.findViewById(R.id.tvPlayerName);
tvPlayerName12.setText(child);
Button btn2=(Button)convertView.findViewById(R.id.button1);
btn2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
TextView tv=(TextView)findViewById(R.id.tv);
tv.setText("Clicked");
}
});
break;
}
return convertView;
}
public int getChildrenCount(int groupPosition) {
return children.get(groupPosition).size();
}
public String getGroup(int groupPosition) {
return groups.get(groupPosition);
}
public int getGroupCount() {
return groups.size();
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String group = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.expandablelistview_group, null);
}
TextView grouptxt = (TextView) convertView.findViewById(R.id.TextViewGroup);
grouptxt.setText(group);
return convertView;
}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int arg0, int arg1) {
return true;
}
}
private void loadData(){
groups= new ArrayList<String>();
childs= new ArrayList<ArrayList<ArrayList<String>>>();
groups.add("Group 1");
groups.add("Group 2");
groups.add("Group 3");
childs.add(new ArrayList<ArrayList<String>>());
childs.get(0).add(new ArrayList<String>());
childs.get(0).get(0).add("Child 1 group 1");
childs.add(new ArrayList<ArrayList<String>>());
childs.get(1).add(new ArrayList<String>());
childs.get(1).get(0).add("Child 1 group 2");
childs.add(new ArrayList<ArrayList<String>>());
childs.get(2).add(new ArrayList<String>());
childs.get(2).get(0).add("Child 1 group 3");
}}
During debugging, If I click any group, it comes to String child=(String)getChild(groupPosition, childPosition).get(0); line. After break; }return convertView;, it comes to there again and again, and then it displays layout.
activity_main.xml
<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" >
<ExpandableListView
android:id="#+id/expandableListView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="34dp" >
</ExpandableListView>
expandablelistview_group.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">
<TextView
android:id="#+id/TextViewGroup"
android:layout_width="wrap_content"
android:layout_height="50px"
android:layout_marginLeft="50px"
android:gravity="center_vertical"
>
</TextView>
child_row.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="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/tvPlayerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />
childrow1.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="match_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Row1" />
<TextView
android:id="#+id/tvPlayerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
Is there any suggestion to solve this.
Thanks
instead of inflating the view from getChildView use Holder read here
Try changing your ExpandableListView xml and instead of android:layout_height="wrap_content", put android:layout_height="fill_parent"