How to update or refresh a listview - android

I'm having a lot of trouble refreshing a list view with a custom adapter. I can't seem to find any solution that will make my list view refresh. I've tried notifyDataSetChanged, and also listView.invalidate, but nothing seems to be working. Any help will greatly be appreaciated. Thanks
Below is the code.
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// Get extra data included in the Intent
Toast.makeText(getApplicationContext(), "Update Chat Ui",
Toast.LENGTH_LONG).show();
commentList.invalidateViews();
commentList.setAdapter(adapter);
adapter.notifyDataSetChanged();
//adapter.notifyDataSetInvalidated();
// adapter.notifyDataSetChanged();
}
};
protected void onPause() {
LocalBroadcastManager.getInstance(this).unregisterReceiver(
mMessageReceiver);
super.onPause();
};
Async task onPost ():
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
try {
adapter = new ListViewAdapter(PrivateMessages.this, arraylist);
commentList.setAdapter(adapter);
adapter.notifyDataSetChanged();
} catch (Exception e) {
} finally {
}
}
Custom Adapter :
public class ListViewAdapter extends BaseAdapter {
// Declare Variables
UserFunctions mUserFunctions;
Context context;
ArrayList<HashMap<String, String>> data;
Preferences mPreferences;
public static int actualPosition;
private static HashMap<String, String> resultp = new HashMap<String, String>();
boolean likeState;
public ListViewAdapter(Context context,
ArrayList<HashMap<String, String>> arraylist) {
this.context = context;
data = arraylist;
mPreferences = new Preferences(context);
mUserFunctions = new UserFunctions();
}
#Override
public int getCount() {
return data.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// Declare Variables
ViewHolder holder = new ViewHolder();
likeState = false;
resultp = data.get(position);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (resultp.get("message_admin").equals(mPreferences.getProfileId())) {
convertView = inflater.inflate(R.layout.comment_listview_item_user,
null);
} else {
convertView = inflater
.inflate(R.layout.comment_listview_item, null);
}
holder.userComment = (TextView) convertView
.findViewById(R.id.comment_item);
holder.commentTime = (TextView) convertView
.findViewById(R.id.time_of_comment);
holder.userComment.setText(resultp.get("message"));
holder.commentTime.setText(resultp.get("message_time"));
return convertView;
}
static class ViewHolder {
TextView userComment;
TextView commentTime;
}
}

try below code:-
myListView.invalidateViews();
Works fine atleast for me.For more information see below link :-
How to refresh Android listview?

You can do following.
arrayList.clear();
arrayList = your new List.
commentList.invalidateViews();
adapter = new ListViewAdapter(PrivateMessages.this, arraylist);
commentList.setAdapter(adapter);

Thanks all, but I finally able to resolve it through the following code:
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
new InitiateChatTask().execute(wish_user_id,
mPreferences.getProfileId());
commentList.invalidateViews();
}
};

Related

android: listview load incorrectly

My listview load properly but when I go back to my MainActivity then again go to ViewAll activity then it load incorrectly like below.
Here is my ViewAll activity where I have load list view.
public class ViewAll extends Activity {
private ListView listView;
public ArrayList<Model> arrayList;
private Database_Handler database_handler;
private SQLiteDatabase db;
private MyAdapter adapter;
private SwipeRefreshLayout swipeContainer;
private long i = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_all);
listView = (ListView) findViewById(R.id.listView);
swipeContainer = (SwipeRefreshLayout) findViewById(R.id.swipeContainer);
addNewData();
database_handler = new Database_Handler(ViewAll.this);
db = database_handler.getReadableDatabase();
arrayList = database_handler.getAllContacts();
adapter = new MyAdapter(ViewAll.this, arrayList);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
try {
database_handler = new Database_Handler(ViewAll.this);
db = database_handler.getReadableDatabase();
arrayList = database_handler.getAllContacts();
adapter = new MyAdapter(ViewAll.this, arrayList);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
swipeContainer.setRefreshing(false);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
private void addNewData() {
try {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
String str1 = "List "+i+" ", str2 = "Handler testing";
database_handler = new Database_Handler(ViewAll.this);
db = database_handler.getWritableDatabase();
database_handler.addRegister(str1, str2, db);
database_handler.close();
handler.postDelayed(this, 60 * 10);
i++;
}
}, 60 * 10);
} catch (Exception e) {
e.printStackTrace();
}
}
}
and here is my adapter.
public class MyAdapter extends BaseAdapter{
private Context context;
private ArrayList<Model> arrayList;
private static LayoutInflater inflater;
public MyAdapter(ViewAll viewAll, ArrayList<Model> arrayList) {
this.context = viewAll;
this.arrayList = arrayList;
}
#Override
public int getCount() {
return arrayList.size();
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
public class Holder {
TextView tvFirstName,tvLastName;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View myView = null;
try {
Holder holder;
myView = convertView;
if (myView == null) {
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
myView = inflater.inflate(R.layout.adapter, null);
holder = new Holder();
holder.tvFirstName= (TextView) myView.findViewById(R.id.tvFirstName);
holder.tvLastName= (TextView) myView.findViewById(R.id.tvLastName);
myView.setTag(holder);
}
else {
holder = (Holder) myView.getTag();
}
holder.tvFirstName.setText(arrayList.get(position).getF_name());
holder.tvLastName.setText(arrayList.get(position).getL_name());
} catch (Exception e) {
e.printStackTrace();
}
return myView;
}
}
Actually I am inserting data into database using handler class and show all data into listview in my ViewAll activity and it work fine but when i go to my previous MainActivity and again go to ViewAll activity then listview load incorrectly which show in the image like after "List 24" data inserted incorrectly.
Please Clear your Arraylist and also clear your adapter when you are loading it from first item of listview.
You can clear this by lstVwList.setAdapter(null);

notifyDataSetChanged not working in AsyncTask inside BaseAdapter class

i have created a list of ads in listview using BaseAdapter and i want to delete a single ad from list. To delete a single ad i have to request a web api using asynchronous task, so i have added the notifyDataSetChanged() in onPostExecute method. ads was deleted successfully but notifydatasetchnaged not working .my custom BaseAdapter class is given below please help to solve this problem.
public class AdsListAdapter extends BaseAdapter{
private Activity activity;
ArrayList<String> title;
ArrayList<Long> adsIds;
SessionManager sessions;
AlertDialogManager alert = new AlertDialogManager();
private static LayoutInflater inflater=null;
String MYTAG="AdLIst";
long userID=0;
public AdsListAdapter(Activity a,ArrayList<String> titlelist,ArrayList<Long> adsId,long userid) {
activity = a;
title=titlelist;
adsIds=adsId;
userID=userid;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
sessions=new SessionManager(activity.getApplicationContext());
imageLoader = new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return title.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView titles,editicon,delicon;
}
#SuppressLint("NewApi") public View getView(int position, View convertView, ViewGroup parent) {
final int id=position;
View vi=convertView;
ViewHolder holder;
if(convertView==null){
vi = inflater.inflate(R.layout.adscustomlist, null);
holder = new ViewHolder();
holder.titles = (TextView) vi.findViewById(R.id.titles);
holder.editicon= (TextView) vi.findViewById(R.id.editicon);
holder.delicon= (TextView) vi.findViewById(R.id.delicon);
vi.setTag( holder );
}
else
{ holder=(ViewHolder)vi.getTag(); }
holder.titles.setText(title.get(position));
holder.delicon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
new DeleteAd(userID,adsIds.get(id)).execute();
}
});
return vi;
}
class DeleteAd extends AsyncTask<String,Void,Void>
{
AlertDialogManager alert = new AlertDialogManager();
private String Error = null,Message=null;
long UserID =0,AdId=0;
boolean Status=false;
private ProgressDialog Dialog = new ProgressDialog(activity);
protected void onPreExecute() {
Dialog.setMessage("Loading ...");
Dialog.setCanceledOnTouchOutside(false);
Dialog.show();
}
public DeleteAd(long UserID,long AdId) {
this.UserID=UserID;
this.AdId=AdId;
}
#Override
protected Void doInBackground(String... arg0) {
JSONObject json;
try {
json = new JSONObject(postDataAdDelete());
Message=json.getString("Message");
Status = json.getBoolean("Status");
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(Void unused) {
Dialog.dismiss();
alert.showAlertDialog(activity, "Ad Delete", Message, Status);
notifyDataSetChanged();
}
}
}
Try to call notifyDataSetChanged() method like this
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
notifyDataSetChanged();
}
});
you must remove value at position you want to delete in list title. Try title.remove(position)
AdsListAdapter adapter = new AdsListAdapter (Activity ,ArrayList<String> ,ArrayList<Long> ,long );//pass the value
adapter.notifyDataSetChanged();

How to create a Multilevel list using listview

The following is my Json data from database, i want to list the interest_name in a list(only if visible is true). List must be multilevel. I parsed the json file using Gson library. But i have no idea regarding how to make a multilevel list using listview.
{"interest_id":0,"interest_name":"ROOT","visible":false,"children":
[{"interest_id":1,"interest_name":"Sports","visible":true,"children":[{"interest_id":2,"interest_name":"Archery","visible":true,"children":[]},{"interest_id":3,"interest_name":"Bow Hunting","visible":true,"children":[]}]},{"interest_id":100,"interest_name":"Contry","visible":true,"children":[{"interest_id":101,"interest_name":"Afghanistan","visible":true,"children":[]},{"interest_id":102,"interest_name":"Akrotiri","visible":true,"children":[]}]},{"interest_id":1000,"interest_name":"Education","visible":true,"children":[]},{"interest_id":1200,"interest_name":"Entertainment","visible":true,"children":[]},{"interest_id":1400,"interest_name":"Books","visible":true,"children":[]},{"interest_id":1600,"interest_name":"Services","visible":true,"children":[]},{"interest_id":1800,"interest_name":"Fitness","visible":true,"children":[]},{"interest_id":2000,"interest_name":"Fashion","visible":true,"children":[]},{"interest_id":99999,"interest_name":"Near Me","visible":false,"children":[]}]}
My code:
Home.java
Intent intent = new Intent( Home.this,InterestAddList.class);
startActivity(intent);
finish();
InterestAddList.java
public class InterestAddList extends Activity {
ListView intrestListView;
OneOnOneListAdapter adapter;
List<String> intrestList;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.intrest_add);
intrestListView = (ListView) findViewById(R.id.InterestList);
//Service Called For retrieving Data
retrieveList();
}
public void retrieveList() {
intrestList = new ArrayList<String>();
StringBuilder urlc = new StringBuilder(urlPrefix + "gai");
String url=urlc.toString();
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE).create();
String result = ServiceClient.getInstance().getResponse(url);
InterestNode ni=gson.fromJson(result, InterestNode.class);
//for(int i=0;i<ni.length;i++){
//Log.e("ni", ni.getInterestName());
//Log.e("ni", String.valueOf(ni.getInterestId()));
/* how to display interest name */
intrestList.add(ni.getInterestName());
}
adapter = new OneOnOneListAdapter(InterestAddList.this,R.layout.intrest_add_row,intrestList);
intrestListView.setAdapter(adapter);
}
private class OneOnOneListAdapter extends ArrayAdapter {
public OneOnOneListAdapter(Context context, int textViewResourceId,
List objects) {
super(context, textViewResourceId, objects);
}
#Override
public long getItemId(int position) {
return super.getItemId(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
final int aposition=position;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.intrest_add_row, null);
}
TextView intrestText =(TextView)v.findViewById(R.id.IntrestText);
intrestText.setText(intrestList.get(aposition).toString());
v.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
System.out.println("OnItem CLicked");
Toast.makeText(InterestAddList.this,"Position clicked:"+intrestList.get(aposition).toString(),Toast.LENGTH_SHORT).show();
Intent i = new Intent(InterestAddList.this,SubIntrestAddList.class);
i.putExtra("position", aposition);
startActivityForResult(i,1);
}
});
return v;
}
}}
InterestNode.java
public class InterestNode {
#SerializedName("interest_id")
int interestId;
#SerializedName("interest_name")
String interestName;
#SerializedName("visible")
boolean isVisible;
transient InterestNode parent;
#SerializedName("children")
List<InterestNode> childList = new ArrayList<InterestNode>();
public List<InterestNode> getChildren(){
return new ArrayList<InterestNode>(childList);
}
public int getInterestId() {
return interestId;
}
public String getInterestName() {
return interestName;
}
public InterestNode getParent() {
return parent;
}
public boolean isVisible() {
return isVisible;
}
public void addChild(InterestNode intNode){
childList.add(intNode);
}
public void setInterestId(int interestId) {
this.interestId = interestId;
}
public void setInterestName(String interestName) {
this.interestName = interestName;
}
public void setParent(InterestNode parent) {
this.parent = parent;
}
public void setVisible(boolean isVisible) {
this.isVisible = isVisible;
}
}
It better to use Expandable ListView to add multilevel list, instead. But you want using listview then follow below nice tutorial here step by step three level listiview is achieved.
Android Multilevel ListView Tutorial
hope it helps you!

OnItemClickListener getting data from model

I am fairly new to Android development and I am trying to build a ListView which get data from web service using gson. I have a model class, a list class, an adapter class and the activity class.
The list works fine and it got the data, and now I want to integrate the OnItemClickListener to it and pass the data to the 2nd activity. And I'd like to get the item id (DistrictId) and pass it to the next Activity(listView) instead of the row id. It would be great if someone could show me the light... as the documentation is not as clear to understand and because I am new.
Below is my code.
The model class
package com.sample.myapp;
public class DistrictModel {
private String id;
private String districtName;
public String getDistrictId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDistrictName(){
return districtName;
}
public void setDistrictEN(String districtName){
this.districtName = districtName;
}
}
The List class
public class DistrictList {
private List<DistrictModel> districts;
public List<DistrictModel> getDistricts(){
return districts;
}
public void setDistrictList(List<DistrictModel> districts){
this.districts = districts;
}
}
The Adapter class
public class DistrictAdapter extends ArrayAdapter<DistrictModel>{
int resource;
String response;
Context context;
private LayoutInflater dInflater;
public DistrictAdapter(Context context, int resource, List<DistrictModel> objects) {
super(context, resource, objects);
this.resource = resource;
dInflater = LayoutInflater.from(context);
}
static class ViewHolder {
TextView title;
}
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
//Get the current location object
DistrictModel lm = (DistrictModel) getItem(position);
//Inflate the view
if(convertView==null)
{
convertView = dInflater.inflate(R.layout.item_district, null);
holder = new ViewHolder();
holder.title = (TextView) convertView
.findViewById(R.id.district_name);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.title.setText(lm.getDistrictName());
return convertView;
}
}
The activity class
public class DistrictListActivity extends Activity{
LocationManager lm;
ArrayList<DistrictModel> districtArray = null;
DistrictAdapter districtAdapter;
DistrictList list;
ListView lv;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.districtlist_layout);
lv = (ListView) findViewById(R.id.list_district);
districtArray = new ArrayList<DistrictModel>();
districtAdapter = new DistrictAdapter(DistrictListActivity.this, R.layout.item_district, districtArray);
lv.setTextFilterEnabled(true);
lv.setAdapter(districtAdapter);
try {
new DistrictSync().execute("http://aws.something.com/service");
} catch(Exception e) {}
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View convertView, int position, long id) {
AlertDialog.Builder adb=new AlertDialog.Builder(DistrictListActivity.this);
adb.setTitle("LVSelectedItemExample");
adb.setMessage("Selected Item is = "+(lv.getItemIdAtPosition(position)));
adb.setPositiveButton("Ok", null);
adb.show();
}
}); **//i'd like to get the DistrictId from the json data.**
}
private class DistrictSync extends AsyncTask<String, Integer, DistrictList> {
protected DistrictList doInBackground(String... urls) {
DistrictList list = null;
int count = urls.length;
for (int i = 0; i < count; i++) {
try {
// ntar diganti service
RestClient client = new RestClient(urls[i]);
try {
client.Execute(RequestMethod.GET);
} catch (Exception e) {
e.printStackTrace();
}
String json = client.getResponse();
list = new Gson().fromJson(json, DistrictList.class);
//
} catch(Exception e) {}
}
return list;
}
protected void onProgressUpdate(Integer... progress) {
}
protected void onPostExecute(DistrictList dislist) {
for(DistrictModel lm : dislist.getDistricts())
{
districtArray.add(lm);
}
districtAdapter.notifyDataSetChanged();
}
}
}
For testing purpose, now I click the row it will show me the row id, so I know the onclick listener works, but I just want it to grab me the DistrictId so I can use it to pass to the next activity.
Thank you so much.
(out of my head) Try this:
((DistrictModel)lv.getAdapter().getItem(position)).getDistrictId();
Generally when you want to pass data from one Activity to another, you just place it into the Intent that you use to create the new Activity.
For example (and here are some additional examples):
Intent i = new Intent(context, MyNewActivity.class);
i.putExtra("MyCurrentHealth", mCurrentHealth);
context.startActivity(i);
To retrieve the data do this:
Bundle extras = getIntent().getExtras();
if (extra != null) {
... // Do stuff with extras
}

Append new elements from custom adapter to ListView

I've got a ListView with a 'show next results' button. The list is filled by a custom adapter extending BaseAdapter. Using it as shown below, only the new results are shown.
How can I append the new results to the list?
ListView listView = (ListView)findViewById(android.R.id.list);
// Show next results button
View footerView = ((LayoutInflater)ItemList.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_listview, null, false);
listView.addFooterView(footerView);
footerView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = getIntent();
i.putExtra("firstIndex", mFirstIndex + NRES_PER_PAGE);
i.putExtra("itemCount", NRES_PER_PAGE);
startActivity(i);
}
});
mItems = json.getJSONArray("data");
setListAdapter(new ItemAdapter(ItemList.this, mType, mItems));
FIX
ListActivity
public class ItemList extends MenuListActivity{
ItemAdapter mItemAdapter;
Integer mFirstIndex = 0;
JSONArray mItems = new JSONArray();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.item_list);
// Set data adapter
mItemAdapter = new ItemAdapter(ItemList.this, mType, mItems);
ListView listView = (ListView)findViewById(android.R.id.list);
View footerView = ((LayoutInflater)ItemList.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_listview, null, false);
listView.addFooterView(footerView);
footerView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
progressDialog = MyProgressDialog.show(ItemList.this, null, null);
mFirstIndex = mFirstIndex + ITEM_COUNT;
new GetItemInfoList().execute();
}
});
setListAdapter(mItemAdapter);
new GetItemInfoList().execute();
}
private class GetItemInfoList extends AsyncTask<Void, Void, JSONObject> {
protected JSONObject doInBackground(Void... params) {
// Set POST data to send to web service
List<NameValuePair> postData = new ArrayList<NameValuePair>(2);
postData.add(new BasicNameValuePair("firstindex", Integer.toString(mFirstIndex)));
postData.add(new BasicNameValuePair("itemscount", Integer.toString(ITEM_COUNT)));
JSONObject json = RestJsonClient.getJSONObject(URL_ITEMINFOLIST, postData);
return json;
}
protected void onPostExecute(JSONObject json) {
try {
// Get data from json object and set to list adapter
JSONArray jsonArray = json.getJSONArray("data");
for(int i=0; i<jsonArray.length(); i++)
mItems.put(jsonArray.get(i));
mItemAdapter.notifyDataSetChanged();
ListView listView = (ListView)findViewById(android.R.id.list);
View footerView = ((LayoutInflater)ItemList.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_listview, null, false);
listView.addFooterView(footerView);
footerView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
progressDialog = MyProgressDialog.show(ItemList.this, null, null);
mFirstIndex = mFirstIndex + ITEM_COUNT;
new GetItemInfoList().execute();
}
});
} catch (JSONException e) {
}
}
}
}
Adapter
public class ItemAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater;
private JSONArray mItems;
private ImageLoader mImageLoader;
private int mCategory;
public ItemAdapter(Context context, int category, JSONArray items) {
mContext = context;
mInflater = LayoutInflater.from(context);
mItems = items;
mCategory = category;
this.mImageLoader = new ImageLoader(context, true);
}
public int getCount() {
return mItems.length();
}
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.item_row, null);
holder = new ViewHolder();
holder.listitem_pic = (ImageView) convertView.findViewById(R.id.listitem_pic);
holder.listitem_desc = (TextView) convertView.findViewById(R.id.listitem_desc);
holder.listitem_title = (TextView) convertView.findViewById(R.id.listitem_title);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
try {
JSONObject item = mItems.getJSONObject(position);
String listitem_pic = item.getString("picture");
holder.listitem_pic.setTag(listitem_pic);
mImageLoader.DisplayImage(listitem_pic, (Activity)mContext, holder.listitem_pic);
holder.listitem_title.setText(item.getString("title"));
holder.listitem_desc.setText(item.getString("desc"));
}
catch (JSONException e) {
}
return convertView;
}
static class ViewHolder {
TextView listitem_title;
ImageView listitem_pic;
TextView listitem_desc;
}
}
It depends on your implementation of ItemAdapter, I'd recommend holding a reference to ItemAdapter, then updating the data set behind it and then calling notifyDataSetChanged() on it. something like:
ItemAdapter ia = new ItemAdapter(ItemList.this, mType, mItems);
setListAdapter(ia);
footerView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mItems.append(newItems);
ia.notifyDataSetChanged();
}
});
It is tricky without knowing what data you are using or whether you have the entire data set available at the start.

Categories

Resources