我在android中有一個不確定進度的問題。我有一個按鈕,點擊按鈕時應該出現不確定的進度條,並且在任務結束時進度條應該消失。android不確定進度條問題
但我無法做到這一點。
package com.indeterminate;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.*;
public class IndeterminateProgressBarActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
final ProgressBar pb=new ProgressBar(this);
pb.setVisibility(View.GONE);
Button b =new Button(this);
b.setText("Click to start spinning");
b.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
pb.setVisibility(View.VISIBLE);
// Want to write some code
pb.setVisibility(View.GONE);
// But the progress bar is not shown on the screen
LinearLayout l=new LinearLayout(this);
l.addView(pb);
l.addView(b);
this.setContentView(l);
}
}
http://stackoverflow.com/questions/3548441/android-create-progressbar-programmatically –
我的問題不在於設置顏色等屬性。它消失 – nikhil
pb.setVisibility(View.VISIBLE); try {0} Thread.sleep(3000); pb.setVisibility(View.GONE); } catch(InterruptedException e){} –