2015-10-07 3 views
0

Это мой код, пожалуйста, предложите, почему Progressbar не станет невидимым, чтобы показать TextView. Сначала я переключаю видимость и на выполнение Post, но получаю только индикатор выполнения, но не отображается текстовое изображение. Любое предложение?Диалоговое окно 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 к GONE в onPostExecute

progressBar.setVisibility(View.GONE); 
+0

Я просто сделал, но до сих пор ничего, индикатор по-прежнему виден – ktk

+0

Попробуйте progressBar.dismiss(); тогда – Jas

Смежные вопросы