因此,在我的AsyncTask类(1,'gekozenOptochtDataParser')中,我执行了另一个AsyncTask
类(2)。在(2)我尝试使GIF可见并消失,但它不起作用。这与布局有关,因为当我在页脚,标题和'MainActivity'中放置'GifTextView
'时它会起作用(页脚和标题是不同的布局),但是当我尝试在' MainActivity
'布局不起作用。我需要使用“RunOnThread
”声明吗?或者问题是什么?
使“GifTextView
”可见并消失的代码(2):
public class removeDialog extends AsyncTask<Void, Void, Void> {
Context c;
//ProgressDialog asyncDialog;
String page;
boolean running;
GifTextView loadingGif;
public removeDialog(GifTextView loadingGif, String page, Context c) {
this.loadingGif = loadingGif;
this.page = page;
this.c = c;
//asyncDialog = new ProgressDialog(c);
}
@Override
protected void onPreExecute() {
loadingGif.setVisibility(View.VISIBLE);
if (page == "algemeneVoorwaarden") {
Intent intent = new Intent(c, algemeneVoorwaarden.class);
c.startActivity(intent);
}
if (page == "contact") {
Intent intent = new Intent(c, contactTest.class);
c.startActivity(intent);
}
super.onPreExecute();
running = true;
}
@Override
protected Void doInBackground(Void... arg0) {
int i = 2;
while(running){
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(i-- == 0){
running = false;
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
//hide the dialog
loadingGif.setVisibility(View.GONE);
super.onPostExecute(result);
}
}
执行类的代码(1,'gekozenOptochtDataParser'):
//footer en header toevoegen
View header = View.inflate(c, R.layout.headergekozenoptocht, null);
View footer = View.inflate(c, R.layout.footer, null);
View gekozenOptochtLayout = View.inflate(c, R.layout.activity_gekozen_optocht, null);
//gif image view pakken
final GifTextView loadingGif = (GifTextView) gekozenOptochtLayout.findViewById(R.id.loading);
voorwaarden.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new removeDialog(loadingGif, "algemeneVoorwaarden", c).execute();
}
});
contact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new removeDialog(loadingGif, "contact", c).execute();
}
});
//header en footer toevoegen
lv.addHeaderView(header, null, false);
lv.addFooterView(footer, null, false);
//adapter toevoegen
lv.setAdapter(adapter);
'MainActivity'中的代码:
new gekozenOptochtDownloader(gekozenOptocht.this, urlAddress, lv).execute();