ProgressBar (進度條)
ListView (很重要的顯示控件)
例 : <ProgressBar android:id="@+id/pBar"
Style="?Android:attr/progressBarStyleHorizontal" -- 水平方向的進度條
Android:layout_width="200dp"
Android:layout_height="wrap_content"
Android:visibility="gone"
Android:max=200
/>
代碼 : 1 . 聲明變量
2 . 根據ID取得控件對象 findViewById
3 . 設置監聽類
Class ButtonLinstener implements OnClickListener {
Public void onClick(View v) {
If (i == 0) {
pBar.setVisibility(View.VISIBLE);
}
Else if ( i < pBar.getMax() ) {
pBar.setProgress(i); -- 設置主進度條的當前值
pBar.setSecondaryProgress(i+10); -- 設置第二進度條的當前值
}
Else {
pBar.setVisbility(View.GONE);
}
I = i + 10;
}
}
4 . 綁定事件
myButton.setOnClickListener(new ButtonLinstener());
例 : main佈局文件
<ListView android:id="@id/android:list"
Android:layout_width="fill_parent"
Android:layout_height="wrap_content"
Android:drawSelecrorOnTop = "false"
Android:scrollbars="vertical" />
User佈局文件略 (兩個TextView)
代碼 : public class Activity extends ListActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 用一個集合對象裝數據
ArrayList<HashMap<Stirng,String>> list = new ArrayList<HashMap<Stirng,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>();
Map1.put("user_name","zhangsan");
Map1put("user_ip","192.168.0.1");
Map2.put("user_name","lisi");
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);
// listActivity對象 , map , 第二個佈局文件 , 對應hashMap的值對(可想象成列) , 控件顯示的位置
SimpleAdapter listAdapter = new SimpleAdapter(this , list , R.layout.user , new String[] {"user_name","user_ip"} , new int[] {R.id.user_ip,R.id.user_name});
setListAdapter(listAdapter);
}
// 重寫
Protected void onListItemClick(ListView lv , View v , int position , long id) {
super.onListItemClick(1, v , position , id);
System.out.println("id--------" + id);
System.out.println("position-------" + position)
}