如何追加在Android的最新数据,自定义基本适配器列表视图? [英] how to append latest data to custom base adapter list view in android?

查看:131
本文介绍了如何追加在Android的最新数据,自定义基本适配器列表视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现在列表view.In我的应用程序已经显示一些内容到列表视图通过使用自定义基本适配器的内容将来自网络service.I已经使用了一个按钮,开始使用自定义的基本适配器的应用程序的显示数据从service.when的最新数据我从服务的最新数据,然后我想追加的最新数据,以列表视图底部,但不删除previous数据列表视图。

我已经实现了我的应用程序如下:

 的结果=新ParseXml()convertMessages(新模型()的getMessages(0)。)。
           计数=的Integer.parseInt(result.get(0).getMessageID());
           ((按钮)findViewById(R.id.oldMessagesButton))。setOnClickListener(新OnClickListener(){

                @覆盖
                公共无效的onClick(视图v){

                fetchNewMessages();

                }
            });



  保护无效fetchOldMessages(){
    // TODO自动生成方法存根
    waitProgreess = ProgressDialog.show(这一点,请稍等,载入中...);
    新的Thread(){
        公共无效的run(){
            尝试 {

                视频下载(800);
                }赶上(InterruptedException异常E){
                }
                newmessageHandler.sendEmptyMessage(0);
        }
    }。开始();
}


  私人处理程序newmessageHandler =新的处理程序(){

    公共无效的handleMessage(信息MSG){
        super.handleMessage(MSG);

        Log.v(0​​00000,伯爵+计);
        如果(计数大于0){
        newmsgResult =新ParseXml()convertMessages(新模型()getNewMessages(+计数)。)。

        CustomeAdapter适配器=新CustomeAdapter(GetMsgsScreen.this,newmsgResult);
        lst.setAdapter(适配器);
        adapter.notifyDataSetChanged();
        数=的Integer.parseInt(newmsgResult.get(oldmsgResult.size() -  1).getMessageID());
    }
        waitProgreess.dismiss();
    }
};
 

我已经实现了一个基于按钮的计数值用户点击上面的code将被发送到服务的话,获得最新的来自service.When我从役的该列表想追加到列表视图的最新列表。

从上面的$ C $词只能得到最新previous被删除。

我怎么能追加在我的上述情况的最新数据(表),以列表视图?

请任何机构可以帮助我......

解决方案

  CustomeAdapter适配器=新CustomeAdapter(GetMsgsScreen.this,newmsgResult);
 

在你class..not顶部定义该适配器和 newmsgResult A类中的局部变量。

现在,每当你想更新列表视图中的数据,更新值 newmsgResult /数据和呼叫 adapter.notifyDataSetChanged()

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);

define this adapter andnewmsgResult at top of your class..not a local variable inside a class..

Now, whenever you want to update the data in list view, update the values/data in newmsgResult and call adapter.notifyDataSetChanged()

这篇关于如何追加在Android的最新数据,自定义基本适配器列表视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆