android多个列表显示,android-如何使列表视图仅显示3个项目

我将发布一个代码,该代码用于在滚动事件中分别填充10条记录.

/**

* Called when the activity is first created.

*

* @param savedInstanceState

* the saved instance state

*/

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.view_checkin_checkout_history);

Thread thread = new Thread() {

public void run() {

synchronized (this) {

fetchHistory(0);

handler.post(new Runnable() {

public void run() {

pd.dismiss();

displayUI();

};

});

}

}

};

thread.start();

}

/**

* Display the check in check out history list.

*/

private void displayUI() {

if ((checkInCheckOutHistoryList != null)

&& (checkInCheckOutHistoryList.size() > 0)) {

historyArrayList = new ArrayList>();

histroyListAdapter = new SimpleAdapter(

ViewCheckInCheckOutHistory.this, historyArrayList,

R.layout.multi_colummn_list_text_style_small, new String[] {

"assetTag", "gif" , "action", "actionTime"},

new int[] { R.id.list_content_column1,

R.id.list_content_imagecolumn,

R.id.list_content_column3,

R.id.list_content_column4});

// To add more items to list view on scroll event.

historyListView.setOnScrollListener(new OnScrollListener() {

@Override

public void onScrollStateChanged(AbsListView view,

int scrollState) {

}

@Override

public void onScroll(AbsListView view, int firstVisibleItem,

int visibleItemCount, int totalItemCount) {

int lastInScreen = firstVisibleItem + visibleItemCount;

if ((lastInScreen == totalItemCount) && !(loadingMore) && (lastInScreen < totalHistoryItemCount)) {

if (!firstInstance) {

openSlider();

}

fetchHistory(lastInScreen);

Thread thread = new Thread(null, loadMoreListItems);

thread.start();

}

}

});

}

}

// Runnable to load the items

private Runnable loadMoreListItems = new Runnable() {

@Override

synchronized public void run() {

// Set flag so we cant load new items 2 at the same time

loadingMore = true;

HashMap historyObjectMap;

for (CheckInCheckOutHistory checkOutHistoryObj : checkInCheckOutHistoryList) {

historyObjectMap = new HashMap();

historyObjectMap.put("assetTag",

checkOutHistoryObj.getAssetTag());

historyObjectMap.put("action", checkOutHistoryObj.getAction());

historyObjectMap.put("actionTime",

checkOutHistoryObj.getActionDate());

if (checkOutHistoryObj.getAction().equals("Checked out")) {

historyObjectMap.put("gif", R.drawable.radio_button_yellow

+ "");

} else {

historyObjectMap.put("gif", R.drawable.radio_button_green

+ "");

}

historyArrayList.add(historyObjectMap);

}

runOnUiThread(returnRes);

}

};

// Since we cant update our UI from a thread this Runnable takes care of

// that!

private Runnable returnRes = new Runnable() {

@Override

public void run() {

// Add the new items to the adapter

if (historyArrayList != null && historyArrayList.size() > 0) {

histroyListAdapter.notifyDataSetChanged();

}

if (firstInstance) {

historyListView.setAdapter(histroyListAdapter);

firstInstance = false;

}

historyListLayout.setVisibility(View.VISIBLE);

// Done loading more.

loadingMore = false;

if ((slidingDrawer.isOpened()) && (!loadingMore)) {

handler.postDelayed(new Runnable() {

@Override

public void run() {

slidingDrawer.close();

slidingDrawer.setVisibility(View.GONE);

}

}, 1000);

}

}

};

fetchHistory(int count)是我用来设置totalHistoryItemCount&的值的方法. checkInCheckOutHistoryList.

希望这会有所帮助.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值