这是我的代码,请说明为什么Progressbar不会隐藏以显示TextView。我最初切换可见性并在Post执行但我只显示进度条但不显示textview。有什么建议吗?
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 :(得分:0)
您必须在int count = 0;
int month = cal.get(Calendar.MONTH);
while (cal.get(Calendar.MONTH) == month) {
count++;
cal.add(Calendar.DATE, 7);
}
System.out.println("This month has " + count + " saturdays");
LocalDate date = LocalDate.now();
LocalDate endOfMonth = date.withDayOfMonth(date.lengthOfMonth());
date = date.withDayOfMonth(1);
System.out.println(date);
date = date.with(ChronoField.DAY_OF_WEEK, DayOfWeek.SATURDAY.getValue());
int count = 0;
while (date.isEqual(endOfMonth) || date.isBefore(endOfMonth)) {
count++;
date = date.plusDays(7);
}
System.out.println("You have " + count + " Saturdays");
到ProgressBar
的展示率
GONE