標籤:
ProgressBar進度條的使用方式:
進度條的.xml聲明:如果不聲明格式,則預設格式為轉圓圈的形式,聲明進度條的visibility為不可見。
<ProgressBar
android:id="@+id/firstBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:visibility="gone"/>
<ProgressBar
android:id="@+id/secondBar"
android:layout_below="@id/firstBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
.java檔案控制進度條的代碼:
firstBar.setVisibility(View.VISIBLE);
secondBar.setVisibility(View.VISIBLE);
firstBar.setMax(200); //設定進度條的最大值
firstBar.setProgress(50); //設定第一進度
firstBar.setSecondaryProgress(60); //設定第二進度
firstBar.setVisibility(View.GONE); //代碼設定不可見
ListView的使用說明:
首先為在listviewmain.xml檔案中為ListView設定布局方式:
<LinearLayout android:id="@+id/listLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbars="vertical">
</ListView>
</LinearLayout>
其次需要給ListView中的內容顯示格式添加相應的xml檔案(user.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/User_name"
android:layout_width="180dp"
android:layout_height="match_parent"
android:singleLine="true"
android:textSize="10pt" />
<TextView
android:id="@+id/User_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="10pt"
android:gravity="right"/>
</LinearLayout>
在.java檔案的onCreate方法中通過ArrayList對象給ListView控制項新增內容:
setContentView(R.layout.listviewmain);
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>();
map1.put("user_name", "zhangsan");
map1.put("user_ip", "192.168.1.1");
map2.put("user_name", "lisi");
map2.put("user_ip", "192.168.1.12");
map3.put("user_name", "wangwu");
map3.put("user_ip", "192.168.1.18");
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_id});
setListAdapter(listAdapter);
通過onListItemClick方法監聽到底點擊了哪個ListView的哪個View:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
//v被點擊控制項的對象,position被點擊控制項的位置,id被點擊控制項的Id
super.onListItemClick(l, v, position, id);
if(id == 0){
//點擊了第一行
}
}
android中ProgressBar和ListView