• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Dynamically create expandablelistview in android

Hi .,
i got one tutorial and worked that tutorial successfully...here am facing some problem.
Here I have developed one app. Here I wish to need the o/p like below format:
*First Group
Artist: artist
Duration: duration
*Second Group
Title: title
But I got the o/p is:
*First Group
Artist: artist
Duration: duration
(Here displayed empty space for title textview)
*Second Group
(Here displayed empty space for artist textview)
(Here displayed empty space for duration textview)
Title: title



How can I do this?

Here I have used below code for my layout file. But I can't get the my requirement output. So please help me and give me some ideas. please help me
This is my android layout code:

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

>

<ExpandableListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ExpandableListView>
</LinearLayout>

group_row.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="170px"
>
<TextView
android:id="@+id/order"
android:text="Order"
android:layout_width="wrap_content"
android:layout_height="70px"
android:layout_marginLeft="70px"
android:gravity="center_vertical"
android:textColor="#FFFFFFFF"
android:textSize="20dip"
android:textStyle="bold"
/>

</LinearLayout>
single_list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<TableRow>

<TextView
android:id="@+id/payment_method1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="Artist"
android:textSize="15dip"
android:textStyle="bold" />

<TextView
android:id="@+id/artist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="artist"
android:textColor="#10bcc9"
android:textSize="15dip"
android:textStyle="bold" />
</TableRow>

<TableRow>

<TextView
android:id="@+id/total1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="Duration"
android:textSize="15dip"
android:textStyle="bold" />

<TextView
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="duration"
android:textColor="#10bcc9"
android:textSize="15dip"
android:textStyle="bold" />
</TableRow>

<TableRow>

<TextView
android:id="@+id/firstname1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="Title"
android:textSize="15dip"
android:textStyle="bold" />

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"
android:text="title"
android:textColor="#10bcc9"
android:textSize="15dip"
android:textStyle="bold" />
</TableRow>

</TableLayout>

This is my android code:
package com.example.androidhive;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.app.ExpandableListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TextView;

import android.widget.ExpandableListView.OnChildClickListener;


public class SingleMenuItemActivity extends ExpandableListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.particular);

// Construct Expandable List
final String NAME1 = "payment_method1";
final String NAME = "artist";
final String TOTAL = "duration";
final String TOTAL1 = "total1";

final String FNAME1 = "firstname1";
final String FNAME = "title";


final LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);



final ArrayList<HashMap<String, String>> headerData = new ArrayList<HashMap<String, String>>();

final HashMap<String, String> group1 = new HashMap<String, String>();
group1.put(NAME, "OrderInfo");
headerData.add( group1 );

final HashMap<String, String> group2 = new HashMap<String, String>();
group2.put(NAME, "CustomerInfo");
headerData.add( group2);




final ArrayList<ArrayList<HashMap<String, Object>>> childData = new ArrayList<ArrayList<HashMap<String, Object>>>();

final ArrayList<HashMap<String, Object>> group1data = new ArrayList<HashMap<String, Object>>();
childData.add(group1data);

final ArrayList<HashMap<String, Object>> group2data = new ArrayList<HashMap<String, Object>>();
childData.add(group2data);


for( int i=0; i<1; ++i) {
final HashMap<String, Object> map = new HashMap<String,Object>();
String s= getIntent().getStringExtra("artist");
String s1= getIntent().getStringExtra("duration");

map.put(NAME1, "Artist:");
map.put(NAME, s );
map.put(TOTAL1, "Total:");
map.put(TOTAL, s1);

group1data.add(map);

}
final HashMap<String, Object> map = new HashMap<String,Object>();
String s1= getIntent().getStringExtra("title");
// String s2= getIntent().getStringExtra("lastname");

map.put(FNAME, s1);
map.put(FNAME1, "Title:");

group2data.add(map);

setListAdapter( new SimpleExpandableListAdapter(
this,
headerData,
R.layout.group_row,
new String[] { NAME, FNAME }, // the names of the data
new int[] { R.id.order }, // the text field to populate with the field data
childData,
0,
null,
new int[] {}
) {
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);

// Populate your custom view here
((TextView)v.findViewById(R.id.payment_method1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(NAME1) );
((TextView)v.findViewById(R.id.artist)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(NAME) );
((TextView)v.findViewById(R.id.title)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(FNAME) );
((TextView)v.findViewById(R.id.firstname1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(FNAME1) );
((TextView)v.findViewById(R.id.total1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(TOTAL1) );
((TextView)v.findViewById(R.id.duration)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(TOTAL) );


return v;
}

@Override
public View newChildView(boolean isLastChild, ViewGroup parent) {
return layoutInflater.inflate(R.layout.single_list_item,null, false);

}
}
);
ExpandableListView list = (ExpandableListView) findViewById(android.R.id.list);
list.setOnChildClickListener(new OnChildClickListener(){
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
System.out.println("Group:"+groupPosition+", Child: "+childPosition);
return true;
}
});
}
}

Here i have to run the app and click the expand means some empty space is displayed here.how can i resolve this error.the screenshot is my o/p.but i wish to need the o/p is w/o empty spaces.please refer screenshot and give me solution.2012-10-04_1347 - Demotrace's library
please give me some solutions and ideas.
Thanks.
 
Back
Top Bottom