My app sets up a list of football team names, and on clicking a textview, the corresponding class is called in a the intent method.
The classes that are called load an xml layout file which is approx 200kb. I would like to implement a progress/loading icon whilst the xml file loads in the background.
I've looked on this site and read about ASynchTask but I don't know what code I need to write in the doInBackground() method.
Here is my class:
I have an array of textviews that get initialised, and an array of classnames assigned to each textview when clicked.
Can anybody help me? I'm a noobie.
As an alternative, is there a way of loading all these classes in the background when the user first clicks on the app?
public class Transfers extends Activity {
public final int[] teams = { R.id.ars, R.id.ast, R.id.bir, R.id.bla,
R.id.blp, R.id.bol, R.id.che, R.id.eve, R.id.ful, R.id.hul,
R.id.lee, R.id.liv, R.id.mid, R.id.mnc, R.id.mnu, R.id.nor,
R.id.nwu, R.id.por, R.id.qpr, R.id.sto, R.id.sun, R.id.swa,
R.id.tot, R.id.wes, R.id.wig, R.id.wol };
public final String[] teamnames = { "ars", "ast", "bir", "bla", "blp",
"bol", "che", "eve", "ful", "hul", "lee", "liv", "mid", "mnc",
"mnu", "nor", "nwu", "por", "qpr", "sto", "sun", "swa", "tot",
"wes", "wig", "wol" };
TextView tv;
Class classname;
String prefix = "ttj.android.ft.teams.";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.m_transfers);
for (int i = 0; i < teams.length; i++) {
final int j = i;
tv = (TextView) findViewById(teams[i]);
tv.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
classname = Class.forName(prefix + teamnames[j]);
Intent open = new Intent(Transfers.this, classname);
startActivity(open);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
});
}
;
}