Android开发中的控件--ProgressBar和ListView

     ProgressBar即进度条,相信对于用户来说并不陌生,当用户等待某一动作的执行时就会出现这个控件提醒用户执行的进度,一种是水平方向的,另一种是圆形的。

    ListView即列表控件,一般Activity继承ListActivity就可以了,并在其中添加相应的适配器即可。

下面是实现的代码:

public class ProgressBar_ListView extends Activity {
	private ProgressBar progressBar1;
	private ProgressBar progressBar2;
	private Button button;
	private Button button2;
	private int i=0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_progress_bar__list_view);
		progressBar1=(ProgressBar)findViewById(R.id.progressbar1);
		progressBar2=(ProgressBar)findViewById(R.id.progressbar2);
		button=(Button)findViewById(R.id.button);
		button2=(Button)findViewById(R.id.button_listview);
		button.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				if(i<progressBar1.getMax()){
					progressBar1.setProgress(i);
					progressBar1.setSecondaryProgress(i+10);
					progressBar2.setProgress(i);
				}
				else if (i>=progressBar1.getMax()) {
					progressBar1.setVisibility(View.GONE);
					progressBar2.setVisibility(View.GONE);
				}
				i+=10;
			}
		});
		button2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			final Intent intent=new Intent(ProgressBar_ListView.this,ListView_Test.class);
			startActivity(intent);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater()
				.inflate(R.menu.activity_progress_bar__list_view, menu);
		return true;
	}

}
public class ListView_Test extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		/*
		 * 注意:这里的ListView控件并不是用户自己的,是系统提供的
		 */
		setContentView(R.layout.listview);
		ArrayList<HashMap<String, String>> list=new ArrayList<HashMap<String,String>>();
		HashMap<String, String> map1=new HashMap<String, String>();
		HashMap<String, String> map2=new HashMap<String, String>();
		HashMap<String, String> map3=new HashMap<String, String>();
		HashMap<String, String> map4=new HashMap<String, String>();
		map1.put("user_name", "wangwang");
		map1.put("user_ip", "192.168.1.1");
		map2.put("user_name", "shiguomin");
		map2.put("user_ip", "192.168.1.2");
		map3.put("user_name", "zhaodong");
		map3.put("user_ip", "192.168.1.3");
		map4.put("user_name", "zhanghu");
		map4.put("user_ip", "192.168.1.4");
		list.add(map1);
		list.add(map2);
		list.add(map3);
		list.add(map4);
		SimpleAdapter listAdapter=new SimpleAdapter(ListView_Test.this, list, R.layout.user_name_ip, 
				new String[]{"user_name","user_ip"},new int[]{R.id.user_name,R.id.user_ip} );
		setListAdapter(listAdapter);
		
	}

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值