android 自动加载下一页,Android-gridview 如何分页加载

下面是一段我写过的sample code,是一个小项目中的adapter的一部分,你可以参考下这个getView的思路来实现那个loading view。

public View getView(int pos, View convertView, ViewGroup parent)

{

Log.e(TAG, "[getView] Begin + This is position:" + pos);

final SongListActivity tempActivity = mParentActivity;

if (tempActivity == null)

{

return convertView;

}

if (mTrackListData == null)

{

return convertView;

}

WrapperSong curSong = null;

if (mTrackListData.size() > pos)

{

curSong = mTrackListData.get(pos);

}

else

{

if (mLoadingView == null)

{

mLoadingView = mInflater.inflate(R.layout.loading_item, null);

mLoadingView.setTag(FLAG_LOADING_ITEM);

}

mPrepareGettingMore = false;

mLoadingViewIsShown = true;

return mLoadingView;

}

return getViewWithPhoto(convertView, curSong, parent, pos);

}

// get list view with four text lines

View getViewWithPhoto(View convertView, WrapperSong curSong, ViewGroup parent, int pos)

{

if (curSong == null)

{

Log.e(TAG, "[getViewWithDescription] curSong cannot be null!");

return convertView;

}

ViewHolder holder;

if (convertView == null || !convertView.getTag().getClass().equals(ViewHolder.class))

{

Log.i(TAG, "convertView == null,Then inflate and new holder");

convertView = mInflater.inflate(R.layout.list_item, parent, false);

holder = new ViewHolder();

holder.listImageView = (ImageView) convertView.findViewById(R.id.ImageView);

holder.listTextView1 = (TextView) convertView.findViewById(R.id.TextView01);

holder.listTextView2 = (TextView) convertView.findViewById(R.id.TextView02);

holder.listTextView3 = (TextView) convertView.findViewById(R.id.TextView03);

convertView.setTag(holder);

}

else

{

Log.d(TAG, "convertView != null,Then get Holder");

holder = (ViewHolder) convertView.getTag();

}

Log.i(TAG, "convertView != null,Then SetValue");

if (holder != null && holder.listImageView != null)

{

holder.listImageView.setTag(new Integer(pos));

String name = curSong.getSongName();

holder.listTextView1.setText("[name]:" + name);

String artist = curSong.getSingerName();

holder.listTextView2.setText("[artist]:" + artist);

String desc = curSong.getSongDescription();

holder.listTextView3.setText("[description]:" + desc);

}

/*

* TODO:If need add cache , you can do something before add to

* decode The bitmap and decodePath will get from cache

*/

String songImageURL = curSong.getSongImage();

MBitmap item = mMemoryCacheBmp.pull(pos);

Bitmap bitmap = (item == null) ? null : item.getBitmap();

String decodePath = (item == null) ? null : item.getPath();

if (bitmap == null || bitmap.isRecycled()

|| (bitmap != null && !TextUtils.equals(decodePath, songImageURL)))

{

Log.d(TAG, "bitmap is null.then add to decode queue");

if (mDecoder != null)

{

Log.d(TAG, "pos:" + pos + ",songImageURL:" + songImageURL);

mDecoder.add(true, pos, songImageURL, pos, songImageURL);

}

else

{

Log.e(TAG, "[getViewWithDescription] mDecoder cannot be null!");

}

if (holder != null && holder.listImageView != null)

{

Log.e(TAG, "[getViewWithPhoto] Set Default Album Icon");

holder.listImageView.setImageBitmap(mDefaultBmp);

}

}

else

{

if (holder != null && holder.listImageView != null)

{

Log.e(TAG, "[getViewWithPhoto] Set Image From Cache");

holder.listImageView.setImageBitmap(bitmap);

}

}

Log.e(TAG, "[getView] end + This is position:" + pos);

return convertView;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值