我想用进度条显示自定义Crouton提醒,我想动态更新进度。这是我的代码,但它不起作用。我怎样才能做到这一点?或者如何在图片上传时显示进度条
private void showCustomViewCrouton() {
// try {
View view = getLayoutInflater().inflate(R.layout.crouton_custom_view,null);
pB = (ProgressBar) view.findViewById(R.id.progressBar1);
final Crouton crouton;
final Configuration croutonConfig = new Configuration.Builder()
.setDuration(Configuration.DURATION_INFINITE)
.setInAnimation(android.R.anim.fade_in)
.setOutAnimation(android.R.anim.fade_out).build();
crouton = Crouton.make(this, view, R.id.croutonContainer, croutonConfig);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crouton.hide(crouton);
}
});
crouton.show();
try{
do{
Thread.sleep(100);
deger+=1;
pB.setProgress(deger);
}while(deger<101);
}catch(Exception e){
}
}
答案 0 :(得分:5)
我是这样做的
final ProgressBar progressBar = new ProgressBar(this,null,android.R.attr.progressBarStyleHorizontal);
progressBar.setIndeterminate(false);
Crouton ct = Crouton.make(this,progressBar);
ct.show();
/* Update it While Showing */
Thread progressUpdateThread = new Thread(new Runnable()
{
@Override
public void run()
{
for(int i=0;i<100;i++)
{
final int progress = i;
runOnUiThread(new Runnable()
{
@Override
public void run()
{
progressBar.setProgress(progress);
}
});
try
{
Thread.sleep(100);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
});
progressUpdateThread.start();
答案 1 :(得分:3)
我想分享我的新代码。我给定制的Crouton充气。我用@Kirtan Patel&#39;代码。再次感谢他。
private void showCustomViewCrouton() {
// try {
View view = getLayoutInflater().inflate(R.layout.crouton_custom_view,null);
pB = (ProgressBar) view.findViewById(R.id.progressBar1);
final Crouton crouton;
final Configuration croutonConfig = new Configuration.Builder()
.setDuration(Configuration.DURATION_INFINITE)
.setInAnimation(android.R.anim.fade_in)
.setOutAnimation(android.R.anim.fade_out).build();
crouton = Crouton.make(this, view, R.id.croutonContainer, croutonConfig);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
crouton.hide(crouton);
}
});
crouton.show();
try{
Thread progressUpdateThread = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 100; i++) {
final int progress = i;
runOnUiThread(new Runnable() {
@Override
public void run() {
pB.setProgress(progress);
}
});
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
progressUpdateThread.start();
}catch(Exception e){
}
}