我需要一些关于如何在自定义对话框布局中与“水平进度”对话框进行交互的信息。这是xml代码:
<?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:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/progressBar1"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:layout_toRightOf="@+id/progressBar1"
android:text="Communicating with Stampii..." />
<ProgressBar
android:id="@+id/progressBar2"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/progressBar1"
android:layout_margin="20dp" />
</RelativeLayout>
以下是我用来创建对话框的代码:
private void createCancelProgressDialog() {
cancelDialog = new AlertDialog.Builder(this);
cancelDialog.setView(getLayoutInflater().inflate(R.layout.sync_bars, null));
cancelDialog.setTitle("Synchronization!");
cancelDialog.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
AlertDialog alert = cancelDialog.create();
alert.show();
}
所以,如果有人有建议,请不要害羞。谢谢!
答案 0 :(得分:4)
View dialogRoot = getLayoutInflater().inflate(R.layout.sync_bars, null);
cancelDialog.setView(dialogRoot);
ProgressBar hbar = (ProgressBar) dialogRoot.findViewById(R.id.progressBar2);
您必须引用您的进度条与其进行互动。