my working task is to read sd card files and i want to show all sdcard files with location on textview but,my code is reading successfully but,i can’t update textview text while reading files is not working after i find solution runonuithread but,it’s also not working.my code is shown below:
public void scan (final File path) {
try
{
for (final File f : path.listFiles()) {
if (f.isFile()) {
scannedfiles=scannedfiles+1;
progresspercentage=scannedfiles*100/FilesCount;
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
lbl_scan.setText("SCANING:"+f.getAbsolutePath());\\first time only change text after didn't change
Toast.makeText(getApplicationContext(),"Files:"+f.getAbsolutePath(),Toast.LENGTH_SHORT).show();
}
});
}
else {
if(!f.getName().equals("Android"))
{
scan(f);
}
}
}
}
catch (Exception e)
{
}
}
i am calling scan function below code:
File root = new File (Environment.getExternalStorageDirectory().getAbsolutePath());
scan(root);
can any one help me greatly appreciated.
You might be calling scan on the UI Thread! This should be obvious if the whole UI is blocking during the operation.
Try: