Hi i have one xml parsing example.here i have to add expanadable listview.how is add here.please help me.
this is my code:
public class SingleMenuItemActivity extends ExpandableListActivity {
static final String KEY_ARTIST = "payment_method";
static final String KEY_SUBTOTAL = "subtotal";
static final String KEY_DISCOUNT = "discount";
#SuppressWarnings("unchecked")
public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent in = getIntent();
String subtotal = in.getStringExtra(KEY_SUBTOTAL);
String discount = in.getStringExtra(KEY_DISCOUNT);
String payment_method = in.getStringExtra(KEY_ARTIST);
TextView lblSub = (TextView) findViewById(R.id.subtotal_label);
TextView lblTotal = (TextView) findViewById(R.id.total_label);
TextView lblPayment = (TextView) findViewById(R.id.payment_label);
lblSub.setText(subtotal);
lbldiscount.setText(discount);
lblPayment.setText(payment_method);
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
createGroupList(), // Creating group List.
R.layout.group_row, // Group item layout XML.
new String[] { "Order Info" }, // the key of group item.
new int[] { R.id.order},
// ID of each group item.-Data under the key goes into this TextView.
createChildList(), // childData describes second-level entries.
R.layout.single_list_item, // Layout for sub-level entries(second level).
new String[] {"payment_label:"}, // Keys in childData maps to display.
new int[] { R.id.payment_label} // Data under the keys above go into these TextViews.
);
setListAdapter( expListAdapter ); // setting the adapter in the list.
}catch(Exception e){
System.out.println("Errrr +++ " + e.getMessage());
}
}
/* Creating the Hashmap for the row */
#SuppressWarnings("unchecked")
private List createGroupList() {
ArrayList result = new ArrayList();
for( int i = 0 ; i < 1 ; ++i ) { // 15 groups........
HashMap m = new HashMap();
m.put( "Order Info","Order Info " + i ); // the key and it's value.
result.add( m );
}
return (List)result;
}
/* creatin the HashMap for the children */
#SuppressWarnings("unchecked")
private List createChildList() {
ArrayList result = new ArrayList();
for( int i = 0 ; i < 2 ; ++i ) { // this -15 is the number of groups(Here it's fifteen)
/* each group need each HashMap-Here for each group we have 3 subgroups */
ArrayList secList = new ArrayList();
for( int n = 0 ; n < 1 ; n++ ) {
HashMap child = new HashMap();
child.put( "payment_label", "payment_label " + n );
secList.add( child );
}
result.add( secList );
}
return result;
}
public void onContentChanged () {
System.out.println("onContentChanged");
super.onContentChanged();
}
/* This function is called on each child click */
public boolean onChildClick( ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {
System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition);
return true;
}
/* This function is called on expansion of the group */
public void onGroupExpand (int groupPosition) {
try{
System.out.println("Group exapanding Listener => groupPosition = " + groupPosition);
}catch(Exception e){
System.out.println(" groupPosition Errrr +++ " + e.getMessage());
}
}
}
if i have to click particular product means it is go to next activity.the next activity have detailed description with expandable button.if i have to click the detailed discription means it is expanded and displayed payment_method,subtotal,discount otherwise it is stay in less.please help me.how is to do....How is develop my code with above application.
my main.xml file is :
<?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"
android:background="#drawable/bkg"/>
<TextView android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No items"/>
Here i got the output is zero...what changes is i can to do here.please help me.
check the below code snippet:
ListView lv;
lv = (ListView) findViewById(R.id.ListView01);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
gotoActivity();
}
});
start your activity in gotoactivity method using startActivityforResult method to take the values
Related
I have successfully produced a ListView, which takes JSON data from a remote MySQL database, and adds the 3 fields (employee no, employee name, and title) to an Output string called
"employees".
This displays on an Android phone, OK, but what I really want to do is display ONLY employee
name and title - and then when this record in the list is clicked on, the I want to display
ONLY employee no in the next Activity.
Using Split String, I have managed to just show "employee no" in the next Activity, but that
still leaves the problem of just showing employee name + title ONLY in the ListView.
If I only add those 2 fields together in the Output string, then "employee no" would be
"invisible" when single item clicked on..
Many thanks in advance!
Here is the relevent code in my MainActivity..
for (int i = 0; i < jsonMainNode.length(); i++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
String name = jsonChildNode.optString("employee name");
String number = jsonChildNode.optString("employee no");
String title = jsonChildNode.optString("title");
String outPut = name + "-" + title + "-" + number;
employeeList.add(createEmployee("employees", outPut));
}
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "Error" + e.toString(),
Toast.LENGTH_SHORT).show();
}
SimpleAdapter simpleAdapter = new SimpleAdapter(this, employeeList,
android.R.layout.simple_list_item_activated_1,
new String[] { "employees" }, new int[] { android.R.id.text1 });
listView.setAdapter(simpleAdapter);
}
You have to create an object of Employee which has three fields
private String emplyeeName;
private String employeeTitle;
private String employeeNum;
Then fill an ArrayList with the data returned from the server, and populate it using a Custom Adapter.
This way you could manage what should appear in the listview item.
hope it'll help. If there is something not obvious do not hesitate to ask. :)
Edit 1:
Here is an example :
The code in onCreate in MainActivity
final ArrayList<Employee> arr = new ArrayList<Employee>();
final ListView lv = (ListView) findViewById(R.id.listView);
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
String EmployeeNum = arr.get(position).getEmployeeNum();
Intent i = new Intent(MainActivity.this, SecondActivity.class);
i.putExtra("EmployeeNum", EmployeeNum);
startActivity(i);
}
});
CustomAdapter adapter = new CustomAdapter(this , R.layout.activity_main , arr);
lv.setAdapter(adapter);
The custom adapter
public class CustomAdapter extends ArrayAdapter<Employee> {
ArrayList<Employee> Info;
private Context context;
CustomAdapter(Context context, int resource, ArrayList<Employee> objects) {
super(context, resource, objects);
// TODO Auto-generated constructor stub
this.context = context;
Info = objects;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
EmployeeItemHolder employeeHolder;
View view = convertView;
if (view == null) {
employeeHolder = new EmployeeItemHolder();
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
view = inflater.inflate(R.layout.custom_row, parent, false);
employeeHolder.title = (TextView) view.findViewById(R.id.tvtextView);
view.setTag(employeeHolder);
} else {
employeeHolder = (EmployeeItemHolder) view.getTag();
}
Employee eItem = (Employee) this.Info.get(position);
employeeHolder.title.setText(eItem.getEmployeeTitle()+"-"+eItem.getEmplyeeName());
return view;
}
private static class EmployeeItemHolder {
TextView title;
}
}
custom_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">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/tvtextView" />
</LinearLayout>
Edit 2:
To integrate with this code convert your employeeList from
ArrayList<String>
to
ArrayList<Employee>
Here is an example :
ArrayList<Employee> employeeList = new ArrayList<Employee>();
for (int i = 0; i < jsonMainNode.length(); i++) {
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
Employee emp = new Employee();
emp.setEmplyeeName(jsonChildNode.optString("employee name"));
emp.setEmployeeTitle(jsonChildNode.optString("title"));
emp.setEmployeeNum(jsonChildNode.optString("employee no"));
employeeList.add(emp);
}
} catch (JSONException e) {
Toast.makeText(getApplicationContext(), "Error" + e.toString(),
Toast.LENGTH_SHORT).show();
}
CustomAdapter adapter = new CustomAdapter(this, R.layout.activity_main, employeeList );
listView.setAdapter(adapter);
hope that'll help you
I have a menu (fishcombovaluemeals), and when the user select more than 1 item i want those
items to appear in a list in another activity (shopping cart) ,i have tried alot but the data
never appears in the shopping cart ! what is wrong in the onitemclick !? ,
I have
fishcombovaluemeal.java
RowItem.java
CustomListViewAdapter.java
fishcombovaluemealsactivitycode:
package com.example.newlist;
public class FishComboValueMeals extends Activity implements
OnItemClickListener {
ImageButton Ib2;
public static final String[] titles = new String[] {
" Fillet-O-Fish (Medium Value Meals) ",
"Fillet-O-Fish (Large Value Meals) ",
"Double Fillet-O-Fish (Medium Value Meals)",
" Double Fillet-O-Fish (Large Value Meals) ",
};
public static final String[] descriptions = new String[] {
"Light, flaky filet of white fish topped with tangy tartar ",
"Light, flaky filet of white fish topped with tangy tartar ",
"2 patties of tender fish filet over a layer of cheese, ",
" 2 patties of tender fish filet over a layer of "
};
public static final Integer[] images = {
R.drawable.imfc1,
R.drawable.imfc2,
R.drawable.imfc3,
R.drawable.imfc4 };
public static final Double[] prices = { 20.0, 22.73, 24.77, 27.04 };
ListView listView;
List<RowItem> rowItems;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_breakfast);
rowItems = new ArrayList<RowItem>();
for (int i = 0; i < titles.length; i++) {
RowItem item = new RowItem (images[i], titles[i], descriptions[i],
prices[i]);
rowItems.add(item);
}
listView = (ListView) findViewById(R.id.list);
CustomListViewAdapter adapter = new CustomListViewAdapter(this,
R.layout.list_item, rowItems);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
Ib2 = (ImageButton) findViewById (R.id.Button02);
Ib2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generatedmethod stub
Intent openStartingPoint = new Intent (getApplicationContext(),ShoppingCart.class);
startActivity (openStartingPoint);
}
});}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Intent i = new Intent(getApplicationContext(), ShoppingCart.class);
i.putExtra("EXTRA", "Item " + (position + 1) + ": " + rowItems.get(position));
startActivity(i);
}
}
get the selected item of list view and send the value via intent
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
String value = lv1.getItemAtPosition(position).toString();
Intent i = new Intent(getApplicationContext(), ShoppingCart.class);
i.putExtra("EXTRA", value);
startActivity(i);
}
and get the value in other activity
Bundle bundle=getIntent().getExtras();
String value=bundle.getString("EXTRA");
You can use a very simple Class which will store your data into it.
I warn you that this class is just a simple proposition how to solve your problem.
It has many weaknesses but it works ; )
You can improve it : )
Just init it at Application Class.
Here is example:
/**
* Manager to handle passing data between Activities
*
* #author Klawikowski
*
*/
public class ManagerBundle implements IConstants
{
public static final String TAG = "ManagerBundle";
private static Hashtable< Integer , Object > sDataTable;
public static void init()
{
Log.i( TAG , "[ManagerBundle] Initializing ..." );
sDataTable = new Hashtable< Integer , Object >();
}
public static void addBundle( int pKey , Object pObjectToPass )
{
Log.i( TAG , "[ManagerBundle] Adding Object to Manager using key: " + pKey );
sDataTable.put( pKey , pObjectToPass );
}
public static Object getBundle( int pKey )
{
Log.i( TAG , "[ManagerBundle] Getting Object from Manager using key: " + pKey );
Object lData = sDataTable.get( pKey );
sDataTable.remove( pKey );
return lData;
}
}
Just simply put an Table / Array or any other container before starting Activity, and collect it from 2nd one ; )
You need to create a singleton array of the menu items. When user performs multi select jst store the selectedindex to an array and then pass that array to the intent.
Here is the tutorial for multi-select listview
http://www.vogella.com/articles/AndroidListView/article.html
Here is the code to send array in intent
Bundle b=new Bundle();
b.putStringArray(key, new String[]{value1, value2});
Intent i=new Intent(context, Class);
i.putExtras(b);
Bundle b=this.getIntent().getExtras();
String[] array=b.getStringArray(key);
You can try this
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
RowItem selItem = rowItems.get(position);//get the selected RowItem from the list
String[] selValues= selItem.getMethodName();//your method name in RowItem.java class
//which returns array
//if you have getter and setters you can access them and put them in array
//String[] selArray = new String[size];//size = number of value you want to supply
//String[0]= selItem.getTitle();//for title
//String[1] = selItem.getDescription();//for description and so on
//then send the array as parameter
// remaining is same as answered by the Jay Gajjar
Bundle b=new Bundle();
b.putStringArray("EXTRA", selArray);
Intent i = new Intent(getApplicationContext(), ShoppingCart.class);
i.putExtras(b);
startActivity(i);
}
and to retrieve the values in the ShoppingCart class
Bundle b=this.getIntent().getExtras();
String[] array=b.getStringArray("EXTRA");
Here is my code.This is kinda noob question.how can I add action to a child in list view .
This code contains an expandable list view whit 3 children and what I need is when I click on each child separately it opens another class like page2.java.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
public class ExpandableListDemo extends ExpandableListActivity {
#SuppressWarnings("unchecked")
public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
createGroupList(), // Creating group List.
R.layout.group_row, // Group item layout XML.
new String[] { "Group Item" }, // the key of group item.
new int[] { R.id.row_name }, // ID of each group item.-Data under the key goes into this TextView.
createChildList(), // childData describes second-level entries.
R.layout.child_row, // Layout for sub-level entries(second level).
new String[] {"Sub Item"}, // Keys in childData maps to display.
new int[] { R.id.grp_child} // Data under the keys above go into these TextViews.
);
setListAdapter( expListAdapter ); // setting the adapter in the list.
}catch(Exception e){
System.out.println("Errrr +++ " + e.getMessage());
}
}
/* Creating the Hashmap for the row */
#SuppressWarnings("unchecked")
private List createGroupList() {
ArrayList result = new ArrayList();
for( int i = 0 ; i < 15 ; ++i ) { // 15 groups........
HashMap m = new HashMap();
m.put( "Group Item","Group Item " + i ); // the key and it's value.
result.add( m );
}
return (List)result;
}
/* creatin the HashMap for the children */
#SuppressWarnings("unchecked")
private List createChildList() {
ArrayList result = new ArrayList();
for( int i = 0 ; i < 15 ; ++i ) { // this -15 is the number of groups(Here it's fifteen)
/* each group need each HashMap-Here for each group we have 3 subgroups */
ArrayList secList = new ArrayList();
for( int n = 0 ; n < 3 ; n++ ) {
HashMap child = new HashMap();
child.put( "Sub Item", "Sub Item " + n );
secList.add( child );
}
result.add( secList );
}
return result;
}
public void onContentChanged () {
System.out.println("onContentChanged");
super.onContentChanged();
}
/* This function is called on each child click */
public boolean onChildClick( ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {
System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition);
return true;
}
/* This function is called on expansion of the group */
public void onGroupExpand (int groupPosition) {
try{
System.out.println("Group exapanding Listener => groupPosition = " + groupPosition);
}catch(Exception e){
System.out.println(" groupPosition Errrr +++ " + e.getMessage());
}
}
}
have a look at onChildClickListener.
Look at this post for how to implement onChildClick().
Also look at Adding listener to child nodes in Expandable List Item.
I have a View with TextViews, ImageViews,... but I want to include some data using an ExpandableList. I don't know how to include this ExpandableList in my View with the other data.
My objetive:
I have all component in one View except the ExpandableList, that I have in other Activity:
OfferDetailsActivity (This is the Activity that shows the View and from here I want to call to ExpandableList)
public class OfferDetailsActivity extends Activity{
final public static String OFERTA = "oferta";
private Oferta oferta = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.offer_details);
oferta = (Oferta)getIntent().getExtras().getParcelable(OFERTA);
View view = new View(this.getBaseContext());
LayoutInflater linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = linflater.inflate(R.layout.offer_details, null);
// poblamos la lista de elementos
TextView precio = (TextView)view.findViewById(R.id.precio_offer_details);
precio.setText(oferta.getPrecio());
ImageView imagen = (ImageView) view.findViewById(R.id.imagen_offer_details);
imagen.setImageBitmap(new GetImages().downloadFile(oferta.getImagen()));
TextView cabecera = (TextView)view.findViewById(R.id.cabecera_offer_details);
cabecera.setText(oferta.getCabecera());
TextView descripcion = (TextView)view.findViewById(R.id.descripcion_offer_details);
descripcion.setText(oferta.getDescripcion());
setContentView(view);
}
}
ExpandableList
public class ExpandableList extends ExpandableListActivity {
#SuppressWarnings("unchecked")
public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.offer_details);
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
createGroupList(), // Creating group List.
R.layout.group_row, // Group item layout XML.
new String[] { "Group Item" }, // the key of group item.
new int[] { R.id.row_name }, // ID of each group item.-Data under the key goes into this TextView.
createChildList(), // childData describes second-level entries.
R.layout.child_row, // Layout for sub-level entries(second level).
new String[] {"Sub Item"}, // Keys in childData maps to display.
new int[] { R.id.grp_child} // Data under the keys above go into these TextViews.
);
setListAdapter( expListAdapter ); // setting the adapter in the list.
}catch(Exception e){
System.out.println("Errrr +++ " + e.getMessage());
}
}
/* Creating the Hashmap for the row */
#SuppressWarnings("unchecked")
private List createGroupList() {
ArrayList result = new ArrayList();
for( int i = 0 ; i < 15 ; ++i ) { // 15 groups........
HashMap m = new HashMap();
m.put( "Group Item","Group Item " + i ); // the key and it's value.
result.add( m );
}
return (List)result;
}
/* creatin the HashMap for the children */
#SuppressWarnings("unchecked")
private List createChildList() {
ArrayList result = new ArrayList();
for( int i = 0 ; i < 15 ; ++i ) { // this -15 is the number of groups(Here it's fifteen)
/* each group need each HashMap-Here for each group we have 3 subgroups */
ArrayList secList = new ArrayList();
for( int n = 0 ; n < 3 ; n++ ) {
HashMap child = new HashMap();
child.put( "Sub Item", "Sub Item " + n );
secList.add( child );
}
result.add( secList );
}
return result;
}
public void onContentChanged () {
System.out.println("onContentChanged");
super.onContentChanged();
}
/* This function is called on each child click */
public boolean onChildClick( ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {
System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition);
return true;
}
/* This function is called on expansion of the group */
public void onGroupExpand (int groupPosition) {
try{
System.out.println("Group exapanding Listener => groupPosition = " + groupPosition);
}catch(Exception e){
System.out.println(" groupPosition Errrr +++ " + e.getMessage());
}
}
}
offer_details.xml
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow>
<TextView android:id="#+id/precio_offer_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="12px" />
<TextView android:id="#+id/cabecera_offer_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="12px" />
</TableRow>
<TableRow>
<ImageView android:id="#+id/imagen_offer_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:id="#+id/descripcion_offer_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="normal"
android:textSize="10px" />
</TableRow>
<TextView android:id="#+id/texto3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="normal"
android:textSize="10px"
android:text="texto3"/>
<TextView android:id="#+id/texto4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="normal"
android:textSize="10px"
android:text="texto4"/>
Move the code from the expandable list activity into the other qctivity and put the necessary bits in the other activities XML file and you should be fine... is there some issue you're having that prevents you from doing this?
I have an expandable list in android and I can fill it with string easily but now I want to add a drawable on each row of the list (a different one on each row), what's the easiest way to do this with the code I already have? Thanks.
public class Physical extends ExpandableListActivity {
public static final int GROUPS = 1;
public SimpleExpandableListAdapter expListAdapter;
private boolean expanded = true;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.phys_sub);
String [] cats = { "phy1", "phys2" };
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
for (int i = 0; i < GROUPS; i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put( "group", "Categories" );
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for( int n = 0 ; n < cats.length ; n++ ) {
Map<String, String> curChildMap = new HashMap<String, String>();
curChildMap.put( "child", cats[n] );
children.add(curChildMap);
}
childData.add(children);
}
expListAdapter =
new SimpleExpandableListAdapter(
/* context */
this,
/* creates Group list */
groupData,
/*Group item layout XML */
R.layout.group_row,
/* the key of each group element (not child's) */
new String[] { "group" },
/* data under the key goes into this TextView */
new int[] { R.id.group_text },
/* creates Child List (sub-level entries) */
childData,
/* layout for children in list */
R.layout.child_sub,
/* the key of each child element */
new String[] { "child" },
/* data under the child keys go into this textView */
new int[] { R.id.child_text }
);
/* sets up and initializes the adapter for the list */
setListAdapter(expListAdapter);
getExpandableListView().setOnGroupExpandListener( new OnGroupExpandListener() {
public void onGroupExpand(int groupPosition) {
expanded = true;
}
});
getExpandableListView().setOnGroupCollapseListener( new OnGroupCollapseListener() {
public void onGroupCollapse(int groupPosition) {
expanded = false;
}
});
if (expanded != false ) {
getExpandableListView().expandGroup(0);
}
}
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, final int childPosition, long id) {
switch (childPosition) {
case 0:
Intent spine_plus_intent = new Intent(Physical.this, SpinePlus.class);
startActivity(spine_plus_intent);
finish();
break;
}
return true;
}
}
you'd define a custom expandable list adapter and redefine the getchildview / getgroupview.
From there you have 2 routes to follow: one, you can programmatically add the imageviews into the child/group view (i'd discourage you from this approach), or you define an xml layout file for the child/group view and inflate it (and possibly edit the content dynamically)
Simple adapters aren't flexible enough to achieve good results. Expecially when you want custom views for their elements. (Not to mention scalability: always project and code keeping in mind that your requirements may enlarge in the future and a flexible base allows more freedom and prevents you from scratching too much code)