如何在Android进度条上设置延迟

时间:2012-04-26 23:01:03

标签: android xml loading android-progressbar

我想要的是设置它以使进度条加载15秒,然后继续下一个活动。

现在活动有:

public class MainActivity extends Activity {

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button btn5 =(Button)findViewById(R.id.button);

    btn5.setOnClickListener(new Button.OnClickListener() {

      public void onClick(View v) {
        Intent myIntent = new Intent();

        myIntent.setAction(Intent.ACTION_VIEW);

        myIntent.setData(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
        setContentView(R.layout.loading);

      }        
    });
  }

}

xml页面有:

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="144dp"
    android:layout_gravity="center_vertical" />

我想知道如何使progressBar1加载15秒然后转到result.xml

1 个答案:

答案 0 :(得分:0)

查看sdk示例代码中包含的api演示中的进度对话框示例。我相信它位于/src/com/example/android/apis/app/AlertDialogSamples.java中。如果你看最底部,它有代码通过延时消息更新进度条。

您的问题有点不清楚,是您发布第一个或第二个活动的代码