写一个有进度条的alertdialog
public class MyProgressDialog extends AlertDialog.Builder{
private ProgressBar progress;
private TextView tv;
public MyProgressDialog(Context context) {
super(context);
// TODO Auto-generated constructor stub
LayoutInflater inflater = LayoutInflater.from(context);
View v =inflater.inflate(R.layout.progress_dialog_layout, null);
progress=(ProgressBar)v.findViewById(R.id.progress_bar);
tv=(TextView)v.findViewById(R.id.please_wait);
setView(v);
}
public AlertDialog show(){
return super.show();
}
}
这个dialog的layout
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayou xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_centerInParent="true"
style="@style/loadingStyle"
/>
<TextView
android:id="@+id/please_wait"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20dip"
android:text="@string/wait"
></TextView>
</LinearLayou>
然后以以下的方式去显示,但是总是有Inflaterexception,不知道是为啥,求高手解答
private Handler mHandler=new Handler(){
public void handleMessage(Message msg){
switch(msg.what){
case 0:
MyProgressDialog progress=new MyProgressDialog(MyOAuthActivity.this);
dialog=progress.show();
break;
case 1:
if(dialog!=null){
dialog.dismiss();
}
}
}
};