【发布时间】:2014-03-16 16:40:51
【问题描述】:
我有一个列表视图,其中填充了从数据库中获取的数据,对于我输入的每条记录,我都输入了一个进度条。从数据库中获取并检查 TextView 背景的颜色,我想将其分配给 ProgressBar。我能怎么做?在getView()方法中我添加了一个ProgressBar。
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
tvC.setBackgroundColor(d.colore);//I would also assign color to the ProgressBar
final ProgressBar mProgress;
mProgress = (ProgressBar)row.findViewById(R.id.progress_e);
mProgress.setMax(100);
final float numero_float = (float) value;
// run progress
new Thread(new Runnable() {
int progressStatus = 0;
Handler handler = new Handler();
public void run() {
while (progressStatus < numero_float) {
progressStatus += 1;
// Update the progress bar and display the current value
handler.post(new Runnable() {
public void run() {
mProgress.setProgress(progressStatus);
}
});
try {
Thread.sleep(40);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
...
...
【问题讨论】:
-
getPrograssDrawable() 你的 ProgressBar 并用你的自定义 ClipDrawable 替换具有 id == android.id.progress 的图层,该 ClipDrawable 剪辑所需的颜色
-
对不起,我不明白。能给我举个例子?谢谢
-
首先获取进度drawable,将其转换为LayerDrawable并用您的自定义ClipDrawable替换id为android.R.id.progress的图层