问题描述
我已经实现了一个带有自定义基本适配器的应用程序,用于在列表视图中显示数据.在我的应用程序中,我使用自定义基本适配器将一些内容显示到列表视图中,该内容将来自 Web 服务.我使用了一个按钮来获取来自服务的最新数据.当我从服务中获取最新数据时,我想将最新数据附加到底部的列表视图中,而不删除列表视图中以前的数据.
I have implemented an application with Custom base adapter for display data in list view.In my application i have displayed some content to list view by using Custom base adapter that content will come from web service.I have used a button for get the latest data from service.when i get the latest data from service then i would like to append the latest data to list view at bottom without deleting previous data in list view.
我已按如下方式实现了我的应用程序:
I have implemented my application as follows:
result = new ParseXml().convertMessages(new Model().getMessages("0"));
count = Integer.parseInt(result.get(0).getMessageID());
((Button)findViewById(R.id.oldMessagesButton)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
fetchNewMessages();
}
});
protected void fetchOldMessages() {
// TODO Auto-generated method stub
waitProgreess = ProgressDialog.show(this, "Please wait", "Loading...");
new Thread() {
public void run() {
try {
Thread.sleep(800);
} catch (InterruptedException e) {
}
newmessageHandler.sendEmptyMessage(0);
}
}.start();
}
private Handler newmessageHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
Log.v("000000", "count :"+count);
if(count>0){
newmsgResult = new ParseXml().convertMessages(new Model().getNewMessages(""+count));
CustomeAdapter adapter = new CustomeAdapter(GetMsgsScreen.this,newmsgResult);
lst.setAdapter(adapter);
adapter.notifyDataSetChanged();
count=Integer.parseInt(newmsgResult.get(oldmsgResult.size()-1).getMessageID());
}
waitProgreess.dismiss();
}
};
我已经实现了基于用户点击按钮计数值的上述代码将被发送到服务然后从服务中获取最新信息.当我从服务中获取最新列表时,该列表会附加到列表视图中.
I have implemented the above code based on user clicking on button count value will be send to service then get latest from service.When i get the latest list from servie the that list would like append to list view.
从上面的代码我只能得到最新的前一个正在删除.
from the above code i can get only latest previous are deleting.
在上述情况下,如何将最新数据(列表)附加到列表视图?
How can i append latest data(list) to listview in my above case?
请任何人帮助我....
please any body help me....
推荐答案
CustomeAdapter adapter = new CustomeAdapter(GetMsgsScreen.this,newmsgResult);
在类的顶部定义此适配器和newmsgResult
..不是类内的局部变量..
define this adapter andnewmsgResult
at top of your class..not a local variable inside a class..
现在,每当您想更新列表视图中的数据时,请更新 newmsgResult
中的值/数据并调用 adapter.notifyDataSetChanged()
Now, whenever you want to update the data in list view, update the values/data in newmsgResult
and call adapter.notifyDataSetChanged()
这篇关于如何将最新数据附加到 android 中的自定义基本适配器列表视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!