jeudi 28 août 2014

Android progressbar while reading a file


Vote count:

0




I need some help with a progress dialog.


What I'm trying to do is use the progress dialog style spinner while the file is being read, when it finishes I want the dialog to dismiss.


As of right now it only loads after the file is found because of the loop. I don't know how to get it to load before the loop starts



public void readFile() {

pb.setMessage("Looking... after, view the tips in the menu bar :) ");
pb.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pb.setIndeterminate(true);
pb.show();
BufferedReader reader = null;
try {
reader = new BufferedReader(
new InputStreamReader(getAssets().open(("account.txt"))));

// do reading, usually loop until end of file reading
String mLine = reader.readLine();// reading each line.
System.out.println("starting to read line in buffer");

while (mLine != null) {
//process line
btn1.setEnabled(false);

if (mLine.toLowerCase().equals(theiraccount)) { // when an account is found stop reading

checking =theiraccount; //trying to set vale of checking to theiraccount
Log.d("if statement in mline",checking);
reader.close();
pb.dismiss();

System.out.println("closed reader");
mLine=null;// trying to stop the loop
btn1.setEnabled(true);

}//end if
else {

}

mLine = reader.readLine();
System.out.println("cheking mLine"+ mLine);

}

} catch (IOException e) {
//log the exception
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
//log the exception
Log.d("Catch buffer","i failed the catch in finally for reading lines");
}
}

}//end buffer reader

if (checking == theiraccount) {
Toast.makeText(this,"im there",Toast.LENGTH_LONG).show();
System.out.println("i just checked if its there");//another test
btn1.setEnabled(true);
tv1.setText("We found your account, click the menu for tips");
pb.dismiss();
} else {
Toast.makeText(this,"im not there",Toast.LENGTH_LONG).show();
btn1.setEnabled(true);
tv1.setText("We cant find your account, sorry dude");
pb.dismiss();
}
}


asked 1 min ago







Android progressbar while reading a file

Aucun commentaire:

Enregistrer un commentaire