android simpleadapter 刷新,求助SimpleAdapter使用notifyDataSetChanged无法刷新Listview

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

今天弄了一下午了,百度也翻遍了 还是没有处理,吧里的大神帮帮忙啊。真的没办法啦 !!!帮我看看。谢谢你们。

package com.example.listtext;

import java.io.IOException;

import java.io.InputStream;

import java.net.HttpURLConnection;

import java.net.MalformedURLException;

import java.net.URL;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import android.app.Activity;

import android.content.Intent;

import android.database.Cursor;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.os.Bundle;

import android.os.Handler;

import android.os.Message;

import android.util.Log;

import android.view.View;

import android.widget.AbsListView;

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.ImageView;

import android.widget.ListView;

import android.widget.SimpleAdapter;

import android.widget.Toast;

import android.widget.AbsListView.OnScrollListener;

import android.widget.AdapterView.OnItemClickListener;

public class CarsClientTest extends Activity {

/** Called when the activity is first created. */

private ListView listView;

private List cars = new ArrayList();

SimpleAdapter adapter;

View footer;

private String result =null;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.listmain);

footer = getLayoutInflater().inflate(R.layout.footer, null);

listView = (ListView)this.findViewById(R.id.listview);

listView.setOnScrollListener(new ScrollListener());

listView.setOnItemClickListener(new ItemClickListener());

try {

cars.addAll(CarService.getJSONLastCars(0,3));

List> data = new ArrayList>();

for(Cars car : cars){

HashMap item = new HashMap();

item.put("picture", car.getPicture());

item.put("vehicletype", car.getVehicletype());

item.put("loadcapacity", car.getLoadcapacity());

item.put("healthstatus",car.getHealthstatus());

data.add(item);

}

adapter = new SimpleAdapter(this, data, R.layout.listitem, new String[]{"picture","vehicletype", "loadcapacity", "healthstatus"}, new int[]{R.id.title1, R.id.title2, R.id.title3, R.id.title4});

listView.addFooterView(footer);//���ҳ��(����ListView���)

listView.setAdapter(adapter);

listView.removeFooterView(footer);

} catch (Exception e) {

e.printStackTrace();

}

}

private final class ItemClickListener implements OnItemClickListener {

public void onItemClick(AdapterView> parent, View view, int position,

long id) {

ListView lView = (ListView) parent;

HashMap order = (HashMap) lView.getItemAtPosition(position);

Intent intent = new Intent();

Bundle bundle = new Bundle();// 该类用作携带数据

Cars cars = new Cars();

/* private String vehicletype;

private String loadcapacity;

private String healthstatus;

private String picture;

*/

cars.setVehicletype((String) order.get("vehicletype"));

cars.setLoadcapacity((String) order.get("loadcapacity"));

cars.setHealthstatus((String) order.get("healthstatus"));

cars.setPicture((String) order.get("picture"));

bundle.putSerializable("cars", cars);

intent.putExtras(bundle);//

intent.setClass(CarsClientTest.this, ViewOneCar.class);

startActivity(intent);

}

}

private int number = 3;//ÿ�λ�ȡ���������

private int maxpage = 3;//�ܹ��ж���ҳ

private boolean loadfinish = true;

private final class ScrollListener implements OnScrollListener{

public void onScrollStateChanged(AbsListView view, int scrollState) {

Log.i("MainActivity", "onScrollStateChanged(scrollState="+ scrollState+ ")");

}

public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

Log.i("MainActivity", "onScroll(firstVisibleItem="+ firstVisibleItem+ ",visibleItemCount="+

visibleItemCount+ ",totalItemCount="+ totalItemCount+ ")");

final int loadtotal = totalItemCount;

int lastItemid = listView.getLastVisiblePosition();//��ȡ��ǰ��Ļ���Item��ID

if((lastItemid+1) == totalItemCount){//�ﵽ��ݵ����һ����¼

if(totalItemCount > 0){

//��ǰҳ

int currentpage = totalItemCount%number == 0 ? totalItemCount/number : totalItemCount/number+1;

int nextpage = currentpage + 1;//��һҳ

if(nextpage <= maxpage && loadfinish){

loadfinish = false;

listView.addFooterView(footer);

//Log.i("linzhencgeng","1111111111111");

new Thread(new Runnable() {

public void run() {

try {

Thread.sleep(2000);

} catch (InterruptedException e) {

e.printStackTrace();

}

try {

cars.clear();

List result = CarService.getJSONLastCars(loadtotal, number);

handler.sendMessage(handler.obtainMessage(100, result));

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}).start();

}

}

}

}

}

Handler handler = new Handler(){

public void handleMessage(Message msg) {

//List cars = CarService.getJSONLastCars(0,2);

cars.addAll((List) msg.obj);

adapter.notifyDataSetChanged();//����ListView����Ѿ�����ı䣬Ҫ��ListView���½�����ʾ

//Log.i("linzhencgeng","qqqqqq");

if(listView.getFooterViewsCount() > 0) listView.removeFooterView(footer);

//Log.i("linzhencgeng","22222");

loadfinish = true;

}

};

}

adapter.notifyDataSetChanged();这个用SimpleAdapter 到底应该怎么刷新啊啊啊啊啊啊啊啊啊要崩溃了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值