Android逐条加载ListView,实现动画更新

配置文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
	
    <ListView 
    android:id="@+id/lvProcessbar"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" />
    
</LinearLayout>

程序:

package com.amaker.app;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class AA extends Activity { 
    public static final int MSG_UPDATE_LIST = 18; 
     
    private ListView mApps; 
    private Context mContext; 
    private List<String> mAppList; 
    private ProgressDialog dialog; 
    private ArrayAdapter mAdapter; 
    private boolean mIsLoaded = false; 
     
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        // TODO Auto-generated method stub 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
          
        // ListView 列表 mApps 
        mApps = (ListView)findViewById(R.id.lvProcessbar); 
        mContext = this; 
        mAppList = new ArrayList<String>(); 
        mAdapter = new ArrayAdapter(mContext, android.R.layout.simple_list_item_1, mAppList); 
        mApps.setAdapter(mAdapter); 
          
        // 设置正在处理窗口 
        dialog = new ProgressDialog(mContext); 
        dialog.setIcon(R.drawable.icon); 
        dialog.setTitle("ProgressDialog"); 
        dialog.setMessage("Please wait while loading application list..."); 
        dialog.setCancelable(false); 
        dialog.show(); 
          
        // 开始动态加载线程 
        mThreadLoadApps.start(); 
          
        mApps.setOnItemClickListener(new AdapterView.OnItemClickListener(){ 
             public void onItemClick(AdapterView<?> parent, View v, int position, 
                     long id) { 
                mAppList.remove(position); 
                 mAdapter.notifyDataSetChanged(); 
             } 
        }); 
          
        // 获取已经安装程序列表 
        PackageManager pm = mContext.getPackageManager(); 
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 
        List<ResolveInfo> list = pm.queryIntentActivities(mainIntent,0); 
          
        // 逐项添加程序,并发送消息更新ListView列表。 
        for (int i=0; i<list.size(); i++) { 
            mAppList.add(list.get(i).loadLabel(pm).toString()); 
            System.out.println("-------------------------->"+(list.get(i).loadLabel(pm).toString()));
            mAdapter.notifyDataSetChanged(); 
        } 
        mIsLoaded = true; 
    } 
     
    private Thread mThreadLoadApps = new Thread(){ 
        @Override 
        public void run() { 
             int i = 0; 
             while (!mIsLoaded) { 
                 try { 
                     sleep(100); 
                 } catch(InterruptedException e) { 
                    e.printStackTrace(); 
                 } 
             } 
             // 关闭正在处理窗口 
             dialog.dismiss(); 
        } 
    }; 
 }


转载: http://www.uplook.cn/index-Index-show-view8968.html#


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值