Android加上base的作用,android-notifyDataSetChanged在BaseAdapter上不起作用

我有一个关于我的活动的列表视图,当我到达listview的末尾时,它调用async并使用json获取新数据.

这是async和baseAdaper代码:

ListAdapter ladap;

private class GetContacts AsyncTask>> {

@Override

protected Void doInBackground(Void... arg0) {

Spots_tab1_json sh = new Spots_tab1_json();

String jsonStr = sh.makeServiceCall(url + page, Spots_tab1_json.GET);

ArrayList> dataC = new ArrayList>();

if (jsonStr != null) {

try {

JSONObject jsonObj = new JSONObject(jsonStr);

contacts = jsonObj.getJSONArray(TAG_CONTACTS);

for (int i = 0; i < contacts.length(); i++) {

JSONObject c = contacts.getJSONObject(i);

String id = new String(c.getString("id").getBytes("ISO-8859-1"), "UTF-8");

String dates = new String(c.getString("dates").getBytes("ISO-8859-1"), "UTF-8");

String price = new String(c.getString("gheymat").getBytes("ISO-8859-1"), "UTF-8");

HashMap contact = new HashMap();

contact.put("id", id);

contact.put("dates", dates);

contact.put("price", price);

dataC.add(contact);

}

}

} catch (JSONException e) {

goterr = true;

} catch (UnsupportedEncodingException e) {

goterr = true;

}

} else {

goterr = true;

}

return dataC;

}

@Override

protected void onPostExecute(ArrayList> result) {

super.onPostExecute(result);

if (!isCancelled() && goterr == false) {

if(ladap==null){

ladap=new ListAdapter(MainActivity.this,result);

lv.setAdapter(ladap);

}else{

ladap.addAll(result);

ladap.notifyDataSetChanged();

}

}

}

public class ListAdapter extends BaseAdapter {

Activity activity;

public ArrayList> list;

public ListAdapter(Activity activity,ArrayList> list) {

super();

this.activity = (Activity) activity;

this.list = list;

}

public void addAll(ArrayList> result) {

Log.v("this",result.size()+" resultsize");

this.list = result;

notifyDataSetChanged();

}

public int getCount() {

return contactList.size();

}

public Object getItem(int position) {

return contactList.get(position);

}

public long getItemId(int arg0) {

return 0;

}

private class ViewHolder {

TextView title,price;

ImageView img ;

//RelativeLayout rl;

}

public View getView(int position, View convertView, ViewGroup parent) {

ViewHolder holder;

LayoutInflater inflater = activity.getLayoutInflater();

if (convertView == null) {

convertView = inflater.inflate(R.layout.item, null);

holder = new ViewHolder();

holder.title = (TextView) convertView.findViewById(R.id.title);

holder.price = (TextView) convertView.findViewById(R.id.price);

convertView.setTag(holder);

} else {

holder = (ViewHolder) convertView.getTag();

}

item = contactList.get(position);

holder.price.setText(item.get("price"));

return convertView;

}

}

我在这里登录,当我到达listView的末尾时,它调用addAll并返回新的30项购买它没有添加到listview,我不知道为什么.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值