Android - cannot refresh ExpendableListView, it freezes - android

I have an ExpandableListView in which if I add some Groups during onCreate() of the activity, it's fine, but if I try to add Groups later on and then do notifyDataSetChanged() the ExpandableListView just freezes - everything else in the activity works, just the Exp.ListView hangs.
Here as you can see I add two Groups (with children) to the Exp.ListView and they function just fine. If I try to call addTeam() though it freezes/hangs.
package org.mytest;
import java.util.ArrayList;
import eigc.doubango.ScreenTeam.ScreenTeamItemGroup;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ImageButton;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.ImageView;
import android.widget.TextView;
public class ScreenTeam extends Activity {
private TeamListAdapter mTeamListAdapter;
private ExpandableListView mTeamList;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen_team);
mTeamListAdapter = new TeamListAdapter(getLayoutInflater());
mTeamList = (ExpandableListView) findViewById(R.id.screen_team_teamslist);
mTeamList.setAdapter(mTeamListAdapter);
mTeamList.setGroupIndicator(null);
/* TEST */
ScreenTeamItemGroup grp1 = new ScreenTeamItemGroup("team1",1);
ScreenTeamItemChild ch1 = new ScreenTeamItemChild("child1");
ScreenTeamItemChild ch2 = new ScreenTeamItemChild("child2");
grp1.addTeamMember(ch1);
grp1.addTeamMember(ch2);
ScreenTeamItemGroup grp2 = new ScreenTeamItemGroup("team2",2);
ScreenTeamItemChild ch3 = new ScreenTeamItemChild("child1");
ScreenTeamItemChild ch4 = new ScreenTeamItemChild("child2");
ScreenTeamItemChild ch5 = new ScreenTeamItemChild("child3");
grp2.addTeamMember(ch3);
grp2.addTeamMember(ch4);
grp2.addTeamMember(ch5);
mTeamListAdapter.addTeam(grp1);
mTeamListAdapter.addTeam(grp2);
}
/*
* Callbacks
*/
/* adds a team */
public void addTeam() {
ScreenTeamItemGroup grp1 = new ScreenTeamItemGroup("team1",1);
ScreenTeamItemChild ch1 = new ScreenTeamItemChild("child1");
ScreenTeamItemChild ch2 = new ScreenTeamItemChild("child2");
grp1.addTeamMember(ch1);
grp1.addTeamMember(ch2);
mTeamListAdapter.addTeam(grp1);
mTeamListAdapter.notifyDataSetChanged();
}
/*
* Aux classes
*/
/* team group item */
static class ScreenTeamItemGroup {
final String mItemText;
final int mIconResId;
final int mTeamID;
public ArrayList<ScreenTeamItemChild> mTeamMembers;
public ScreenTeamItemGroup(String itemText, int id) {
mItemText = itemText;
mTeamID = id;
mIconResId = R.drawable.teams;
mTeamMembers = new ArrayList<ScreenTeamItemChild>();
}
public void addTeamMember(ScreenTeamItemChild member) {
if (member != null)
mTeamMembers.add(member);
}
}
/* team child item */
static class ScreenTeamItemChild {
final int mIconResId;
final String mItemText;
public ScreenTeamItemChild(String itemText) {
mIconResId = R.drawable.p2p;
mItemText = itemText;
}
}
/* handles the list of teams */
static class TeamListAdapter extends BaseExpandableListAdapter {
public ArrayList<ScreenTeamItemGroup> mTeams;
private final LayoutInflater mInflater;
public TeamListAdapter(LayoutInflater inflater) {
mInflater = inflater;
mTeams = new ArrayList<ScreenTeamItemGroup>();
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return mTeams.get(groupPosition).mTeamMembers.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) {
View view = convertView;
final ScreenTeamItemChild item = (ScreenTeamItemChild)getChild(groupPosition,childPosition);
if(item == null){
return null;
}
if (view == null) {
view = mInflater.inflate(R.layout.screen_team_item, null);
}
((TextView) view.findViewById(R.id.screen_team_item_text)).setText(item.mItemText);
((ImageView) view.findViewById(R.id.screen_team_item_icon)).setImageResource(item.mIconResId);
return view;
}
#Override
public int getChildrenCount(int groupPosition) {
return mTeams.get(groupPosition).mTeamMembers.size();
}
#Override
public Object getGroup(int groupPosition) {
return mTeams.get(groupPosition);
}
#Override
public int getGroupCount() {
return mTeams.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view = convertView;
final ScreenTeamItemGroup item = (ScreenTeamItemGroup)getGroup(groupPosition);
if(item == null){
return null;
}
if (view == null) {
view = mInflater.inflate(R.layout.screen_team_item, null);
}
((TextView) view.findViewById(R.id.screen_team_item_text)).setText(item.mItemText);
((ImageView) view.findViewById(R.id.screen_team_item_icon)).setImageResource(item.mIconResId);
return view;
}
#Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return false;
}
public void addTeam(ScreenTeamItemGroup grp) {
if (grp != null)
mTeams.add(grp);
}
}
}

A few things:
You don't want to make your TeamListAdapter a static subclass.
Try putting the logic for adding a team into an AsyncTask as this could freeze up the UI thread.
Also, what are your logs saying?

I solved this by using runOnUiThread in my addTeam() instead and it worked flawlessly.

Related

How can I Pass Name & Country from Entry Item

I am developer a Apps which contain Various Name & Country List. I want to pass Employee Name & Country name to another activity on click on Child Item of Expandable ListView.
How to set On Click Listener Method on my Activity?
package nasir.main.activity;
import java.util.ArrayList;
import nasir.adapter.EntryItem;
import nasir.adapter.MyListAdapter;
import nasir.adapter.SectionItem;
import nasir.bd.poem.R;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.SearchView;
public class Employee_List extends Activity implements SearchView.OnQueryTextListener, SearchView.OnCloseListener {
Button Collapse;
Button Expand;
private SearchView search;
private MyListAdapter listAdapter;
private ExpandableListView myList;
private ArrayList<SectionItem> section = new ArrayList<SectionItem>();
ArrayList<EntryItem> items = new ArrayList<EntryItem>();
ExpandableListView expandableList = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.poem_list);
expandableList = (ExpandableListView) findViewById(R.id.expandableList);
Expand = (Button) findViewById(R.id.Expand);
Collapse = (Button) findViewById(R.id.Collapse);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
search = (SearchView) findViewById(R.id.search);
search.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
search.setIconifiedByDefault(false);
search.setOnQueryTextListener(this);
search.setOnCloseListener(this);
Collapse.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
int count = listAdapter.getGroupCount();
for (int i = 0; i < count; i++){
myList.collapseGroup(i);
}
Collapse.setVisibility(View.GONE);
Expand.setVisibility(View.VISIBLE);
}
});
Expand.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
int count = listAdapter.getGroupCount();
for (int i = 0; i < count; i++){
myList.expandGroup(i);
}
Expand.setVisibility(View.GONE);
Collapse.setVisibility(View.VISIBLE);
}
});
// display the list
displayList();
// expand all Groups
// expandAll();
collapseAll();
}
// method to expand all groups
private void expandAll() {
int count = listAdapter.getGroupCount();
for (int i = 0; i < count; i++) {
myList.expandGroup(i);
}
}
//method to Collapse all groups
private void collapseAll() {
int count = listAdapter.getGroupCount();
for (int i = 0; i < count; i++){
myList.collapseGroup(i);
}
}
// method to expand all groups
private void displayList() {
// display the list
load_Part_1_Data();
// get reference to the ExpandableListView
myList = (ExpandableListView) findViewById(R.id.expandableList);
// create the adapter by passing your ArrayList data
listAdapter = new MyListAdapter(Poem_List.this, section);
// attach the adapter to the list
myList.setAdapter(listAdapter);
myList.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView arg0, View arg1, int arg2,
int arg3, long arg4) {
// TODO Auto-generated method stub
Intent intent = new Intent(Poem_List.this, Details_Information.class);
startActivity(intent);
return false;
}
});
}
private void load_Part_1_Data() {
items = new ArrayList<EntryItem>();
section.add(new SectionItem(R.drawable.ic_launcher, "", items));
items.add(new EntryItem(R.drawable.ic_launcher, "Margerate Milan", "Computer Operator", getString(R.string.app_name)));
items.add(new EntryItem(R.drawable.ic_launcher, "Abraham Jhon", "Salse Man", getString(R.string.app_name)));
items = new ArrayList<EntryItem>();
section.add(new SectionItem(R.drawable.blank_image, "", items));
items.add(new EntryItem(R.drawable.ic_launcher, "England", "Europe", getString(R.string.app_name)));
items.add(new EntryItem(R.drawable.ic_launcher, "Japan", "Asia", getString(R.string.app_name)));
}
#Override
public boolean onClose() {
listAdapter.filterData("");
expandAll();
return true;
}
#Override
public boolean onQueryTextChange(String query) {
listAdapter.filterData(query);
expandAll();
return true;
}
#Override
public boolean onQueryTextSubmit(String query) {
listAdapter.filterData(query);
expandAll();
return false;
}
}
MyListAdapter.Class
package nasir.adapter;
import java.util.ArrayList;
import nasir.bd.poem.R;
import nasir.main.activity.Details_Information;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class MyListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<SectionItem> continentList;
private ArrayList<SectionItem> originalList;
public MyListAdapter(Context context, ArrayList<SectionItem> continentList) {
this.context = context;
this.continentList = new ArrayList<SectionItem>();
this.continentList.addAll(continentList);
this.originalList = new ArrayList<SectionItem>();
this.originalList.addAll(continentList);
}
#Override
public Object getChild(int groupPosition, int childPosition) {
ArrayList<EntryItem> countryList = continentList.get(groupPosition).getSectionList();
return countryList.get(childPosition);
}
#Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
#Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View view, ViewGroup parent) {
final EntryItem country = (EntryItem) getChild(groupPosition, childPosition);
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.child_row, null);
}
ImageView Rank = (ImageView) view.findViewById(R.id.Rank);
TextView Poem = (TextView) view.findViewById(R.id.Poem);
TextView Poetry = (TextView) view.findViewById(R.id.Poetry);
Rank.setImageResource(country.getRank());
Poem.setText(country.getPoem().trim());
Poetry.setText(country.getPoetry().trim());
view.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, Details_Information.class);
Bundle bundle=new Bundle();
intent.putExtras(bundle);
intent.putExtra("header", country.getDetails_Doc());
context.startActivity(intent);
}
});
return view;
}
#Override
public int getChildrenCount(int groupPosition) {
ArrayList<EntryItem> countryList = continentList.get(groupPosition).getSectionList();
return countryList.size();
}
#Override
public Object getGroup(int groupPosition) {
return continentList.get(groupPosition);
}
#Override
public int getGroupCount() {
return continentList.size();
}
#Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
#Override
public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent) {
SectionItem continent = (SectionItem) getGroup(groupPosition);
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.group_row, null);
}
TextView heading = (TextView) view.findViewById(R.id.heading);
heading.setText(continent.getName().trim());
ImageView Group_icon = (ImageView) view.findViewById(R.id.Group_Icon);
Group_icon.setImageResource(continent.getIcon());
return view;
}
#Override
public boolean hasStableIds() {
return true;
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public void filterData(String query) {
query = query.toLowerCase();
Log.v("MyListAdapter", String.valueOf(continentList.size()));
continentList.clear();
if (query.isEmpty()) {
continentList.addAll(originalList);
} else {
for (SectionItem continent : originalList) {
ArrayList<EntryItem> countryList = continent.getSectionList();
ArrayList<EntryItem> newList = new ArrayList<EntryItem>();
for (EntryItem country : countryList) {
if (country.getPoem().toLowerCase().contains(query) || country.getPoetry().toLowerCase().contains(query) ) {
newList.add(country);
}
}
if (newList.size() > 0) {
SectionItem nContinent = new SectionItem(continent.getIcon(), continent.getName(), newList);
continentList.add(nContinent);
}
}
}
Log.v("MyListAdapter", String.valueOf(continentList.size()));
notifyDataSetChanged();
}
}
In the Employee_List activity , you can access the data through index of child and group obtaining from ChildClickListener
myList.setOnChildClickListener(new OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView arg0, View arg1, int arg2,
int arg3, long arg4) {
// TODO Auto-generated method stub
//Here You can access the child data by
final EntryItem country = (EntryItem) listAdapter .getChild(arg2, arg3);
//From here you can pass the data through Intent
...
return false;
}
});

Android ExpandableListView notifyDataSetChanged

I have got problem with my code in Android application.
I have expandable list view with some data.
Periodically after 2 seconds, I use command NotifyDataSetChanged to update my all data.
The problem is that I have a seekbar and if I change progress then after this 2 seconds, the data was updated and the progress stops changing.
I don't know what I can do to update only row in expandable list view some row but not all.
final Handler handler = new Handler();
timer3 = new Timer();
czyUruchomionoTimer=true;
TimerTask doAsynchronousTask = new TimerTask() {
#Override
public void run() {
handler.post(new Runnable() {
public void run() {
exAdpt.notifyDataSetChanged();
}
});
}
};
timer3.schedule(doAsynchronousTask, 100, 2000);
}
Here is code of my Adapter:
package akme.akmewiz_new;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class ListAdapter_Exp extends BaseExpandableListAdapter {
private List<List_KategoriaObiekty> catList;
private Context ctx;
private LayoutInflater inflater;
private ExpandableListView list;
private String numerIP;
int tempMax = 35;
int tempMin = 10;
private String numerID;
Boolean wejscie = false;
int max = (tempMax-tempMin)*2 ;
final private static int DIALOG_LOGIN = 1;
public ListAdapter_Exp(List<List_KategoriaObiekty> catList, Context ctx, String ip, String ID, Boolean wejscie) {
this.catList = catList;
this.ctx = ctx;
this.inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.numerIP= ip;
this.numerID = ID;
this.wejscie=wejscie;
}
#Override
public Object getChild(int groupPosition, int childPosition) {
return catList.get(groupPosition).getItemList();
}
#Override
public long getChildId(int groupPosition, int childPosition) {
Object obj = catList.get(Integer.valueOf(numerID)).getItemList().get(groupPosition+2);
Lista_menu menus = (Lista_menu) obj;
return menus.getTabelaNazwaItem(childPosition).hashCode();
}
#Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
ViewHolder holder;
final int tempgroupPos = groupPosition;
View v = convertView;
Object obj = catList.get(Integer.valueOf(numerID)).getItemList().get(groupPosition+2);
Lista_menu menus = (Lista_menu) obj;
if(true){
holder = new ViewHolder();
v = inflater.inflate(getLayoutId(ctx,"list_exp_"+menus.getTabelaSposobPrezentacji(childPosition)),null);
Log.d("TAGS","list_exp_"+menus.getTabelaSposobPrezentacji(childPosition));
list = (ExpandableListView) parent.findViewById(R.id.listExp);
if(menus.getTabelaSposobPrezentacji(childPosition).equals("0")) {
holder.item_nazwa = (TextView) v.findViewById(R.id.item_0_nazwa);
holder.item_wartosc = (TextView) v.findViewById(R.id.item_0_wartosc);
Log.d("TAGS","tworze0 "+menus.getTabelaSposobPrezentacji(childPosition));
}
if(menus.getTabelaSposobPrezentacji(childPosition).equals("1")) {
holder.item_nazwa = (TextView) v.findViewById(R.id.item_0_nazwa);
holder.Seek = (SeekBar) v.findViewById(R.id.seekTemp);
holder.Lab1 = (TextView) v.findViewById(R.id.tvLabel1);
holder.Lab3 = (TextView) v.findViewById(R.id.tvLabel3);
holder.Seek.setTag(childPosition + 1);
Log.d("TAGS","tworze1 "+menus.getTabelaSposobPrezentacji(childPosition));
}
v.setTag(holder);
}else{
holder = (ViewHolder) v.getTag();
}
if(menus.getTabelaSposobPrezentacji(childPosition).equals("0")){
holder.item_nazwa.setText(menus.getTabelaNazwaItem(childPosition));
holder.item_wartosc.setText(menus.getTabelaWartoscItem(childPosition));
Log.d("TAGS","wpisuje "+menus.getTabelaSposobPrezentacji(childPosition));
}
if(menus.getTabelaSposobPrezentacji(childPosition).equals("1")){
holder.item_nazwa.setText(menus.getTabelaNazwaItem(childPosition));
holder.Lab1.setText("10.0" + " \u2103");
holder.Lab3.setText("35.0" + " \u2103");
holder.Seek.setMax(max);
Log.d("TAGS","wpisuje "+menus.getTabelaSposobPrezentacji(childPosition));
holder.Seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
notifyDataSetChanged();
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
float przelicznik = (float) ((progress / 2.0) + 10.0);
View view = (View) seekBar.getParent();
if (view != null) {
TextView tvProgress2 = (TextView) view.findViewById(R.id.tvLabel2);
TextView tvProgress1 = (TextView) view.findViewById(R.id.tvLabel1);
TextView tvProgress3 = (TextView) view.findViewById(R.id.tvLabel3);
tvProgress1.setText(Float.toString(tempMin) + " \u2103");
tvProgress2.setText(Float.toString(przelicznik) + " \u2103");
tvProgress3.setText(Float.toString(tempMax) + " \u2103");
}
Object obj = catList.get(Integer.valueOf(numerID)).getItemList().get(tempgroupPos+2);
Lista_menu menus = (Lista_menu) obj;
String ustaw = Float.valueOf(przelicznik).toString();
menus.setTabelaWartoscItem2(ustaw,childPosition);
}
});
String str1 = menus.getTabelaWartoscItem2(childPosition);
if(wejscie){
str1 = menus.getTabelaWartoscItem(childPosition);
wejscie=false;
}
int ustaw1 =(int)(( ( ( (Float.parseFloat(str1.replaceAll("\\D+","")))/10)*2)-20));
holder.Seek.setProgress(ustaw1);
}
return v;
}
#Override
public int getChildrenCount(int groupPosition) {
Object obj = catList.get(Integer.valueOf(numerID)).getItemList().get(groupPosition+2);
Lista_menu menus = (Lista_menu) obj;
return menus.ilosc();
}
#Override
public Object getGroup(int groupPosition) {
return catList.get(groupPosition+2);
}
#Override
public int getGroupCount() {
int ilosc = catList.get(Integer.valueOf(numerID)).getItemList().size();
return ilosc-2;
}
#Override
public long getGroupId(int groupPosition) {
return catList.get(Integer.valueOf(numerID)).hashCode();
}
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
GroupViewHolder holder;
View v = convertView;
if(v==null || !isExpanded || isExpanded){
holder = new GroupViewHolder();
v = inflater.inflate(R.layout.list_group_item_exp,null);
list = (ExpandableListView) parent.findViewById(R.id.listExp);
holder.groupName = (TextView) v.findViewById(R.id.groupName);
holder.groupImage = (ImageView) v.findViewById(R.id.groupImage);
holder.groupIndicator = (ImageView) v.findViewById(R.id.imageView5);
holder.groupImage.setTag(groupPosition + 11);
list.setDividerHeight(8);
v.setTag(holder);
}else{
holder = (GroupViewHolder) v.getTag();
}
if(isExpanded){
holder.groupIndicator.setImageResource(R.mipmap.arrow_g);
}else{
holder.groupIndicator.setImageResource(R.mipmap.arrow_d);
}
holder.groupName.setTextColor(Color.parseColor("#e3e9e4"));
list.setDividerHeight(8);
List<Object> lista = catList.get(Integer.valueOf(numerID)).getItemList();
Object obj = lista.get(groupPosition + 2);
v.setBackgroundResource(R.drawable.lista_obiekty_niebieski);
Lista_menu menu = (Lista_menu) obj;
String obraz = menu.getObrazek();
holder.groupImage.setImageResource(getImageId(ctx,"ico_" + obraz));
holder.groupName.setText(menu.getNazwaGrupy());
return v;
}
#Override
public boolean hasStableIds() {
return true;
}
public static int getImageId(Context context, String imageName) {
return context.getResources().getIdentifier("mipmap/" + imageName, null, context.getPackageName());
}
public static int getLayoutId(Context context, String name) {
return context.getResources().getIdentifier("layout/" + name, null, context.getPackageName());
}
#Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
class ViewHolder {
TextView item_nazwa, item_wartosc, Lab1, Lab3, Lab2;
SeekBar Seek;
}
class GroupViewHolder {
TextView groupName;
ImageView groupImage, groupIndicator;
}
}

I need animation in ExpandableLIstView in onGroupExpand and onGroupCollapse

I am new in android and badly need to do animation in ExpandableLIstView in onGroupExpand and onGroupCollapse.
Please help me.
Given below is my code -
My MainActivity is
package comsam.myexpandablelistviedjsonapp;
import android.app.ProgressDialog;
import android.net.ParseException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.view.animation.PathInterpolatorCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Interpolator;
import android.view.animation.TranslateAnimation;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.Toast;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private ExpandListAdapter ExpAdapter;
private ExpandableListView ExpandList;
private Interpolator easeInOutQuart = PathInterpolatorCompat.create(0.77f, 0f, 0.175f, 1f);
private int lastExpandedPosition = -1;
ArrayList<Parent> list = new ArrayList<Parent>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView animatedButton = (ImageView) findViewById(R.id.parent_img);
ExpandList = (ExpandableListView)findViewById(R.id.exp_list);
new JSONAsyncTask().execute("http://local.agdits.com.bd/hrdemo/expandable.php");
ExpAdapter = new ExpandListAdapter(MainActivity.this, list);
ExpandList.setAdapter(ExpAdapter);
//to show which list has been clicked for Expand
ExpandList.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
#Override
public void onGroupExpand(final int groupPosition) {
if (lastExpandedPosition != -1 && groupPosition != lastExpandedPosition) {
ExpandList.collapseGroup(lastExpandedPosition);
// setupLayoutAnimationClose(groupPosition);
// new AnimUtils().collapse(ExpandList);
}
lastExpandedPosition = groupPosition;
}
});
//to show which list has been clicked for Collapse
ExpandList.setOnGroupCollapseListener(new ExpandableListView.OnGroupCollapseListener() {
#Override
public void onGroupCollapse(int parentPosition) {
Toast.makeText(getBaseContext(), ExpAdapter.getGroupName(parentPosition) + " is collapse ", Toast.LENGTH_LONG).show();
}
});
//to show which Child has been clicked
ExpandList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v, int parentPosition, int childPosition, long id) {
Toast.makeText(getBaseContext(), ExpAdapter.getChildName(parentPosition, childPosition) + " from category " + ExpAdapter.getGroupName(parentPosition) + " is selected", Toast.LENGTH_LONG).show();
return false;
}
});
}
private void expand1() {
System.out.println("I am here expand");
}
private void collapse() {
System.out.println("I am here collapse");
}
class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {
ProgressDialog dialog;
#Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(MainActivity.this);
dialog.setMessage("Loading, please wait");
dialog.setTitle("Connecting server");
dialog.show();
dialog.setCancelable(false);
}
#Override
protected Boolean doInBackground(String... urls) {
try {
//------------------>>
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
//System.out.println(data);
ArrayList<Child> ch_list;
JSONArray jsonArray1 = new JSONArray(data);
for (int i = 0; i < jsonArray1.length(); i++) {
JSONObject object = jsonArray1.getJSONObject(i);
// System.out.println(object.getString("_id"));
Parent parent = new Parent();
parent.setParentName(object.getString("CategoryName"));
parent.setParentImage(object.getString("CatImage"));
//System.out.println(object.getString("CategoryName"));
//Make Child List Array
ch_list = new ArrayList<Child>();
JSONArray childArray = object.getJSONArray("child");
//System.out.println(childArray.length());
for (int j = 0; j < childArray.length(); j++) {
JSONObject childobject = childArray.getJSONObject(j);
Child child = new Child();
child.setName(childobject.getString("name"));
child.setImage(childobject.getString("image"));
ch_list.add(child);
}
// System.out.println(childArray);
//Child List to Parent Items
parent.setItems(ch_list);
list.add(parent);
}
return true;
}
//------------------>>
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean result) {
dialog.cancel();
ExpAdapter.notifyDataSetChanged();
if(result == false) {
Toast.makeText(getApplicationContext(), "Unable to fetch data from server", Toast.LENGTH_LONG).show();
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
My ExpandListAdapter class is
package comsam.myexpandablelistviedjsonapp;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.InputStream;
import java.util.ArrayList;
/**
* Created by tanvinn on 10/27/2015.
*/
public class ExpandListAdapter extends BaseExpandableListAdapter{
private Context context;
private ArrayList<Parent> parents;
public MainActivity activity;
public ImageLoader imageLoader;
public int lastExpandedGroupPosition=-1;
public ExpandListAdapter(Context context, ArrayList<Parent> parents) {
this.context = context;
this.parents = parents;
// Create ImageLoader object to download and show image in list
// Call ImageLoader constructor to initialize FileCache
imageLoader = new ImageLoader(activity);
}
#Override
public Object getChild(int parentPosition, int childPosition) {
ArrayList<Child> chList = parents.get(parentPosition).getItems();
return chList.get(childPosition);
}
#Override
public long getChildId(int parentPosition, int childPosition) {
return childPosition;
}
#Override
public View getChildView(int parentPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
Child child = (Child) getChild(parentPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.child_layout, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.child_txt);
ImageView imageView = (ImageView)convertView.findViewById(R.id.child_img);
imageView.setImageResource(R.drawable.geofence1);
tv.setText(child.getName().toString());
//new DownloadImageTask(imageView).execute(child.getImage().toString());
imageLoader.DisplayImage(child.getImage().toString(), imageView);
return convertView;
}
#Override
public int getChildrenCount(int parentPosition) {
ArrayList<Child> chList = parents.get(parentPosition).getItems();
return chList.size();
}
#Override
public Object getGroup(int parentPosition) {
return parents.get(parentPosition);
}
#Override
public int getGroupCount() {
return parents.size();
}
#Override
public long getGroupId(int parentPosition) {
return parentPosition;
}
#Override
public View getGroupView(int parentPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
Parent parent1 = (Parent) getGroup(parentPosition);
if (convertView == null) {
LayoutInflater inf = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inf.inflate(R.layout.parent_layout, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.parent_txt);
ImageView imageView = (ImageView)convertView.findViewById(R.id.parent_img);
imageView.setImageResource(R.drawable.geofence1);
tv.setText(parent1.getParentName());
// new DownloadImageTask(imageView).execute(parent1.getParentImage().toString());
imageLoader.DisplayImage(parent1.getParentImage().toString(), imageView);
return convertView;
}
#Override
public boolean hasStableIds() {
return false;
}
#Override
public boolean isChildSelectable(int parentPosition, int childPosition) {
return true;
}
public Object getGroupName(int parentPosition) {
Parent parent1 = (Parent) getGroup(parentPosition);
String parentName = parent1.getParentName();
return parentName;
}
public Object getChildName(int parentPosition, int childPosition) {
Child child = (Child) getChild(parentPosition, childPosition);
String childName = child.getName();
return childName;
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
}
Thanks in advance.
You can try with this AnimatedExpandableListView
listView = (AnimatedExpandableListView) findViewById(R.id.listView);
listView.setAdapter(YOUR_ADAPTER);
// In order to show animations, we need to use a custom click handler
// for our ExpandableListView.
listView.setOnGroupClickListener(new OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
// We call collapseGroupWithAnimation(int) and
// expandGroupWithAnimation(int) to animate group
// expansion/collapse.
if (listView.isGroupExpanded(groupPosition)) {
listView.collapseGroupWithAnimation(groupPosition);
} else {
listView.expandGroupWithAnimation(groupPosition);
}
return true;
}
});
Android ExpandableListView using animation
Animation for expandableListView
The following in item_animation_fall_down.xml (Place this xml file in res/anim folder)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"android:duration="500">
<translate android:interpolator="#android:anim/accelerate_decelerate_interpolator"
android:fromYDelta="50%p" android:toYDelta="0" />
<alpha android:fromAlpha="0" android:toAlpha="1"
android:interpolator="#android:anim/accelerate_decelerate_interpolator" />
</set>
The following in getGroupView(....) {} block
convertView.setAnimation(AnimationUtils.loadAnimation(_context,R.anim.item_animation_fall_down));
The following in Activity class
expListView.setAnimation(AnimationUtils.loadAnimation(this,R.anim.item_animation_from_right));
The following in activity_home.xml ( to the root element)
android:fillAfter="true" android:fillEnabled="true"

Get item selected on filterable listview

I came across a nice filterable listview tutorial and I was wondering how to determine what listview item is selected and display a toast. Here is the code:
package com.example.listview;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;
public class TestFilterListView extends Activity {
FrameLayout historyContainer;
ViewStub viewStub;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.history_container);
historyContainer = (FrameLayout) findViewById(R.id.historyContainerLayout);
EditText filterEditText = (EditText) findViewById(R.id.filter_text);
filterEditText.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
historyContainer.removeAllViews();
final List<String> tempHistoryList = new ArrayList<String>();
tempHistoryList.addAll(historyList);
for(String data : historyList) {
if(data.indexOf((s.toString())) == -1) {
tempHistoryList.remove(data);
}
}
viewStub = new ViewStub(TestFilterListView.this, R.layout.history_schedule);
viewStub.setOnInflateListener(new ViewStub.OnInflateListener()
{
public void onInflate(ViewStub stub, View inflated)
{
setUIElements(inflated, tempHistoryList);
}
});
historyContainer.addView(viewStub);
viewStub.inflate();
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
setViewStub();
}
/********************************************************************************************************/
private void setViewStub()
{
historyList.add("first");
historyList.add("second");
historyList.add("third");
historyList.add("fourth");
historyList.add("fifth");
historyList.add("sixth");
historyList.add("seventh");
viewStub = new ViewStub(TestFilterListView.this, R.layout.history_schedule);
viewStub.setOnInflateListener(new ViewStub.OnInflateListener()
{
public void onInflate(ViewStub stub, View inflated)
{
setUIElements(inflated, historyList);
}
});
historyContainer.addView(viewStub);
viewStub.inflate();
}
/********************************************************************************************************/
final List<String> historyList = new ArrayList<String>();
String displayName = "";
ListView historyListView;
private void setUIElements(View v, List<String> historyLists)
{
if (v != null)
{
historyScheduleData.clear();
//historyList.clear();
historyScheduleData.addAll(historyLists);
historyListView = (ListView) findViewById(R.id.historylist);
historyListView.setAdapter(new BeatListAdapter(this));
registerForContextMenu(historyListView);
}
}
private static class BeatListAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public BeatListAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return historyScheduleData.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.history_list_view, null);
holder = new ViewHolder();
holder.historyData = (TextView) convertView
.findViewById(R.id.historytext);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.historyData.setText(historyScheduleData.get(position));
return convertView;
}
static class ViewHolder {
TextView historyData;
}
}
private static final List<String> historyScheduleData = new ArrayList<String>();
}
I thought about using
protected void onListItemClick(ListView l, View v, int position, long id) {
if(position == 0) {
Intent intent = new Intent(getApplicationContext(), GODoc1Activity.class);
startActivity(intent);
But when I try to implement it, it does not work. Am I missing something here? How do I go about doing this?
you tried this?: (in the onCreate)
historyListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
//your code
}
});
If you are trying to find the selected item in your ListView:
listView.getAdapter().getItem(listView.getCheckedItemPosition());
Take a look at the documentation here for more information http://developer.android.com/reference/android/widget/AbsListView.html#getCheckedItemPosition%28%29

when scroll up & down in expandable list views get change

Im using an expandable list in my app,my question is when i scroll up and down in the list, views get changed, please let me know how to fix this
Thanks,
Sam.
below is the code
package com.test.android;
import java.util.ArrayList;
import java.util.Random;
import android.app.ExpandableListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ExpandableListAdapter;
import android.widget.TextView;
/**
* Demonstrates expandable lists using a custom {#link ExpandableListAdapter}
* from {#link BaseExpandableListAdapter}.
*/
public class ExpandableList1 extends ExpandableListActivity {
MyExpandableListAdapter mAdapter;
ProgressDialog progressDialog;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up our adapter
mAdapter = new MyExpandableListAdapter(this);
setListAdapter(mAdapter);
}
/**
* A simple adapter which maintains an ArrayList of photo resource Ids.
* Each photo is displayed as an image. This adapter supports clearing the
* list of photos and adding a new photo.
*
*/
private Handler actionhandler = new Handler(){
/* (non-Javadoc)
* #see android.os.Handler#handleMessage(android.os.Message)
*/
#Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
mAdapter.notifyDataSetChanged();
progressDialog.dismiss();
}
};
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
private ArrayList<String> groups = new ArrayList<String>();
private ArrayList<ArrayList<String>> children = new ArrayList<ArrayList<String>>();
private Context context;
public MyExpandableListAdapter(Context context) {
super();
this.context = context;
groups.add("People Names");
groups.add("Dog Names");
groups.add("Cat Names");
groups.add("Fish Names");
ArrayList<String> child1 = new ArrayList<String>();
child1.add("Arnold-1");
child1.add("Barry-2");
child1.add("Chuck-3");
child1.add("David-4");
child1.add("Arnold-5");
child1.add("Barry-6");
child1.add("Chuck-7");
child1.add("David-8");
child1.add("Arnold-9");
child1.add("Barry-10");
child1.add("Chuck-11");
child1.add("David-12");
child1.add("Arnold-13");
child1.add("Barry-14");
child1.add("Chuck-15");
child1.add("David-16");
children.add(child1);
ArrayList<String> child2 = new ArrayList<String>();
child2.add("Ace-17");
child2.add("Bandit-18");
child2.add("Cha-Cha-19");
child2.add("Deuce-20");
children.add(child2);
ArrayList<String> child3 = new ArrayList<String>();
child3.add("Fluffy-21");
child3.add("Snuggles-22");
child3.add("Fluffy-23");
child3.add("Snuggles-24");
child3.add("Fluffy-25");
child3.add("Snuggles-26");
child3.add("Fluffy-27");
child3.add("Snuggles-28");
child3.add("Fluffy-29");
child3.add("Snuggles-30");
child3.add("Fluffy-31");
child3.add("Snuggles-32");
child3.add("Fluffy-33");
child3.add("Snuggles-34");
children.add(child3);
ArrayList<String> child4 = new ArrayList<String>();
child4.add("Goldy-35");
child4.add("Bubbles-36");
child4.add("dummy-37");
child4.add("Goldy-38");
child4.add("Bubbles-39");
child4.add("dummy-40");
child4.add("Goldy-41");
child4.add("Bubbles-42");
child4.add("dummy-43");
child4.add("Goldy-44");
child4.add("Bubbles-45");
child4.add("dummy-46");
child4.add("Goldy-47");
child4.add("Bubbles-48");
child4.add("dummy-49");
children.add(child4);
}
public Object getChild(int groupPosition, int childPosition) {
return children.get(groupPosition).get(childPosition);
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
//if childern not avaibles.
return children.get(groupPosition).size();
}
private void getMoreData(int groupPosition, int childPosition){
Log.e("getMoreData", "calling groupPosition:"+groupPosition +"|childPosition:"+childPosition);
//remove the dummay record
children.get(groupPosition).remove(childPosition);
//adding a new group with data.
Random randomGenerator = new Random();
int count = randomGenerator.nextInt(100);
groups.add("More Data:" + count);
ArrayList<String> newData = new ArrayList<String>();
newData.add("Arnold"+count);
newData.add("Barry"+ count);
newData.add("Chuck"+ count);
newData.add("David"+ count);
children.add(newData);
//removing a record from exssitng group.
children.get(0).remove(0);
children.get(0).add("add to group0 shaggy");
//adding a record to group
children.get(1).add("shaggy add to group 2 shaggy");
//remove a groiup and corresponding childrens
groups.remove(2);
children.remove(2);
//adding a new record to last group.
children.get(groups.size()-1).add("new record");
//adding a dummy record to last group.
children.get(groups.size()-1).add("dummy");
}
public TextView getGenericView() {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 64);
TextView textView = new TextView(ExpandableList1.this);
textView.setLayoutParams(lp);
// Center the text vertically
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
textView.setPadding(36, 0, 0, 0);
return textView;
}
public Button getGenericButton(final int groupPosition,final int childPosition) {
// Layout parameters for the ExpandableListView
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT, 64);
Button button = new Button(ExpandableList1.this);
button.setText("More");
button.setLayoutParams(lp);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
progressDialog = ProgressDialog.show(context, null, "Please Wait");
new Thread(){
/* (non-Javadoc)
* #see java.lang.Thread#run()
*/
#Override
public void run() {
getMoreData(groupPosition,childPosition);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
actionhandler.sendEmptyMessage(0);
}
}.start();
}
});
// Center the text vertically
button.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
button.setPadding(36, 0, 0, 0);
return button;
}
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
Log.e("getChildView", groupPosition + "===" +groups.size());
if(convertView == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.chilldlayout_data, null);
// parent.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
}
if( groupPosition == groups.size()-1 && isLastChild){
//adding a button.
Button button = (Button)convertView.findViewById(R.id.more_button);
button.setVisibility(View.VISIBLE);
button.setText("More");
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
progressDialog = ProgressDialog.show(context, null, "Please Wait");
new Thread(){
/* (non-Javadoc)
* #see java.lang.Thread#run()
*/
#Override
public void run() {
getMoreData(groupPosition,childPosition);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
actionhandler.sendEmptyMessage(0);
}
}.start();
}
});
// Center the text vertically
button.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
// Set the text starting position
button.setPadding(36, 0, 0, 0);
return convertView;
}else{
Button button = (Button)convertView.findViewById(R.id.more_button);
button.setVisibility(View.GONE);
TextView textView = (TextView)convertView.findViewById(R.id.textView_data);
textView.setText(getChild(groupPosition, childPosition).toString());
return convertView;
}
}
public Object 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) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
public boolean hasStableIds() {
return true;
}
}
}

Categories

Resources