Android 具有直线进度条的Listview
我刚接触安卓系统,现在正试图做一个小项目。 它包括一个带有Android 具有直线进度条的Listview,android,android-listview,android-progressbar,Android,Android Listview,Android Progressbar,我刚接触安卓系统,现在正试图做一个小项目。 它包括一个带有textview的listview和一个线性progressbar(其值不需要更改)。 简单适配器用于将数据填充到文本视图。 但是要设置progressbar值,应该使用哪个适配器。 我无法想象如何将值设置为progressbar。 请帮忙 这是我的密码: main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http:/
textview
的listview
和一个线性progressbar
(其值不需要更改)。
简单适配器
用于将数据填充到文本视图
。
但是要设置progressbar
值,应该使用哪个适配器。
我无法想象如何将值设置为progressbar
。
请帮忙
这是我的密码:
main.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">
<ListView
android:id="@+id/dblist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:background="@drawable/image_bg"
android:layout_marginRight="5dip">
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/ic_launcher"/>
</LinearLayout>
<!-- Title Of Song-->
<TextView
android:id="@+id/col1tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:text="Rihanna Love the way lie"
android:textColor="#040404"
android:typeface="sans"
android:textSize="15dip"
android:textStyle="bold"/>
<!-- Artist Name -->
<TextView
android:id="@+id/col2tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/col1tv"
android:textColor="#343434"
android:textSize="10dip"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/thumbnail"
android:text="Just gona stand there and ..." />
<TextView
android:id="@+id/package_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/col1tv"
android:textColor="#343434"
android:textSize="10dip"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/col2tv"
android:text=" puzzles, 0 solved" />
<!-- Rightend Duration -->
<!-- Rightend Arrow -->
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
list_row.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">
<ListView
android:id="@+id/dblist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:background="@drawable/image_bg"
android:layout_marginRight="5dip">
<ImageView
android:id="@+id/list_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/ic_launcher"/>
</LinearLayout>
<!-- Title Of Song-->
<TextView
android:id="@+id/col1tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:text="Rihanna Love the way lie"
android:textColor="#040404"
android:typeface="sans"
android:textSize="15dip"
android:textStyle="bold"/>
<!-- Artist Name -->
<TextView
android:id="@+id/col2tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/col1tv"
android:textColor="#343434"
android:textSize="10dip"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/thumbnail"
android:text="Just gona stand there and ..." />
<TextView
android:id="@+id/package_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/col1tv"
android:textColor="#343434"
android:textSize="10dip"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/col2tv"
android:text=" puzzles, 0 solved" />
<!-- Rightend Duration -->
<!-- Rightend Arrow -->
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
main.java
String[] from = new String[] {"id", "name", "size"};
int[] to = new int[] { R.id.id, R.id.name, R.id.size };
// prepare the list of all records
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < pkg_id_col.size(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", id_col.get(i));
map.put("name", name_col.get(i));
map.put("size", size.get(i));
fillMaps.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.list_row_add_new, from, to);
lv_add_new.setAdapter(adapter);
String[]from=新字符串[]{“id”、“name”、“size”};
int[]to=newint[]{R.id.id,R.id.name,R.id.size};
//准备所有记录的清单
List fillMaps=new ArrayList();
对于(int i=0;i
SimpleAdapter只知道如何为文本视图
和图像视图
绑定数据。要绑定您的ProgressBar
,请使用simpledapter.ViewBinder
:
String[] from = new String[] {"id", "name", "size", "progress"};
int[] to = new int[] { R.id.id, R.id.name, R.id.size, R.id.theIdOfTheProgressBar}; // it seems that you don't have a `ProgressBar` in the layout
// prepare the list of all records
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < pkg_id_col.size(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", id_col.get(i));
map.put("name", name_col.get(i));
map.put("size", size.get(i));
map.put("progress", valueForProgressBar); // progress will hold the progress for your ProgressBar
fillMaps.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.list_row_add_new, from, to);
adapter.setViewBinder(new SimpleAdapter.ViewBinder() {
public boolean setViewValue(View view, Object data, String textRepresentation) {
if (view.getId == R.id.theIdOfTheProgressBar) {
((ProgressBar) view).setProgress(Integer.parseInt(data));
return true;
}
return false;
}
});
String[]from=新字符串[]{“id”、“name”、“size”、“progress”};
int[]to=new int[]{R.id.id,R.id.name,R.id.size,R.id.theIdOfTheProgressBar};//似乎布局中没有“ProgressBar”
//准备所有记录的清单
List fillMaps=new ArrayList();
对于(int i=0;i
使用与您相同的适配器有什么问题?错误是“ProgressBar不是一个可以被此SimpleAdapter绑定的视图”。它不是一个视图,但它显示在listview的所有行中?显然,您将有不同的数据来显示不同的进度值,因此这些值将来自一些数据的收集。将它放在那里,并将适配器放在数据集合中。