android应用开发笔记---常用控件ProcessBar和ListView

也就是进度条和列表控件


第一个是水平进度条,进度条可以设置两个进度 如一个表示 下载进度 另一个表示处理数据进度 

第二个进度条是android默认的,不能设置进度

相关代码和布局文件

package mars.progressbar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;

public class ProgressBarTest extends Activity {
    /** Called when the activity is first created. */
	//声明变量
	private ProgressBar firstBar =null;
	private ProgressBar secondBar = null;
	private Button myButton = null;
	private int i = 0 ;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //根据控件的ID来取得代表控件的对象
        firstBar = (ProgressBar)findViewById(R.id.firstBar);
        secondBar = (ProgressBar)findViewById(R.id.secondBar);
        myButton = (Button)findViewById(R.id.myButton);
        myButton.setOnClickListener(new ButtonListener());
    }
    class ButtonListener implements OnClickListener{
    	
		@Override
		public void onClick(View v) {
			if(i == 0)
			{
				//设置进度条处于可见的状态
				firstBar.setVisibility(View.VISIBLE);
				firstBar.setMax(150);
				secondBar.setVisibility(View.VISIBLE);
			}
			else if ( i < firstBar.getMax()){
				//设置主进度条的当前值
				firstBar.setProgress(i);
				//设置第二进度条的当前值
				firstBar.setSecondaryProgress(i + 10);
				//因为默认的进度条无法显示进行的状态
				//secondBar.setProgress(i);
				
			}
			else{
				//设置进度条处于不可见状态
				firstBar.setVisibility(View.GONE);
				secondBar.setVisibility(View.GONE);
			}
			i = i + 10 ;
		}
    	
    }
    
}

布局







另外一个就是ListView

package mars.listview;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class Activity01 extends ListActivity {
    /** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		ArrayList> list = new ArrayList>();
		HashMap map1 = new HashMap();
		HashMap map2 = new HashMap();
		HashMap map3 = new HashMap();
		map1.put("user_name", "zhangsan");
		map1.put("user_ip", "192.168.0.1");
		map2.put("user_name", "zhangsan");
		map2.put("user_ip", "192.168.0.2");
		map3.put("user_name", "wangwu");
		map3.put("user_ip", "192.168.0.3");
		list.add(map1);
		list.add(map2);
		list.add(map3);
		SimpleAdapter listAdapter = new SimpleAdapter(this, list,
				R.layout.user, new String[] { "user_name", "user_ip" },
				new int[] { R.id.user_name,R.id.user_ip});
		setListAdapter(listAdapter);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);
		System.out.println("id----------------" + id);
		System.out.println("position----------" + position);
	}

}


Adapt有几列listview,string中就有几个
相关布局文件



	
		
	





	
	


显示结果



你可能感兴趣的:(android应用)