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); } }