0
這是我的代碼,請建議爲什麼進度條不能隱藏以顯示TextView。我在初始階段和執行後切換可見性,但我只看到進度條顯示,但沒有顯示文本視圖。任何建議?Android對話框,更改窗口小部件的可見性
public class myClass extends BaseActivity implements View.OnClickListener{
Button mSaveButton;
final Context context = this;
Dialog dialog;
TextView text;
ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
getSupportActionBar().hide();
mSaveButton = (Button)findViewById(R.id.saveBtn);
findViewById(R.id.txt_left_menu).setOnClickListener(this);
findViewById(R.id.saveBtn).setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.saveBtn){
dialog = new Dialog(context);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.alert_layout);
text = (TextView) dialog.findViewById(R.id.text);
progressBar = (ProgressBar) dialog.findViewById(R.id.progressBar);
progressBar.setVisibility(View.VISIBLE);
text.setVisibility(View.INVISIBLE);
dialog.show();
new myTask().execute();
}
}
class myTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
// some preExecute statements
}
@Override
protected Void doInBackground(Void... params) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// some execution statements
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
progressBar.setVisibility(View.INVISIBLE);
text.setVisibility(View.VISIBLE);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
dialog.dismiss();
finish();
}
@Override
public void onBackPressed() {
finish();
}
}
這是我的警告框的佈局是一個自定義對話框,這樣我就可以得到一個進度條。
<?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="fill_parent">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Payment Received"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="@+id/progressBar"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
我只是做了,但仍然沒有,進度條仍然可見 – ktk
嘗試progressBar.dismiss();然後 – Jas