2015-10-07 52 views
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> 

回答

0

你要的ProgressBar可见性改变,以GONEonPostExecute

progressBar.setVisibility(View.GONE); 
+0

我只是做了,但仍然没有,进度条仍然可见 – ktk

+0

尝试progressBar.dismiss();然后 – Jas