【发布时间】:2021-05-27 10:57:42
【问题描述】:
我的进度对话框有问题。出现进度对话框,但我看不到任何进展。我不知道我做错了什么。这是我的代码:
case R.id.fill_metal_pieces_table:
MyApplication myApp = ((MyApplication)getActivity().getApplicationContext());
boolean tablepopulated = myApp.getMetalPiecesTablePopulated();
if(tablepopulated == false){
myApp.setMetalPiecesTablePopulated(true);
progressDialog = new ProgressDialog(getContext());
progressDialog.setIndeterminate(false);
progressDialog.setMax(652);
progressDialog.setMessage("Chargement...");
progressDialog.setTitle("Remplissage de la table");
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setCancelable(false);
progressDialog.show();
new Thread(new Runnable() {
public void run() {
Looper.prepare();
handler = new Handler(Looper.myLooper()){
public void handleMessage(Message msg) {
super.handleMessage(msg);
progressDialog.incrementProgressBy(msg.what);
}
};
Looper.loop();
AssetManager am = getContext().getAssets();
InputStream is = null;
try {
is = am.open("catalogue.xls");
} catch (IOException e) {
e.printStackTrace();
}
Workbook wb = null;
try {
wb = Workbook.getWorkbook(is);
} catch (IOException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
}
Sheet sheet = wb.getSheet(0);
DBAdapter db = new DBAdapter(getContext());
MetalPiece metalPiece;
for(int row = 1; row <= 652; row ++){
String typeMetalPiece = sheet.getCell(0, row).getContents();
String weightMetalPiece = sheet.getCell(1, row).getContents();
metalPiece = new MetalPiece();
metalPiece.setType(typeMetalPiece);
metalPiece.setWeight(Float.parseFloat(weightMetalPiece));
metalPiece.setFamily("Profile");
metalPiece.setUnit("Métre");
db.saveMetalPiece(metalPiece);
handler.sendEmptyMessage(1);
}
progressDialog.dismiss();
intent = new Intent(getContext(), MainActivity.class);
intent.putExtra("tab","metalpiece");
startActivity(intent);
}
}).start();
}
else{
Toast statusMetalPiecesTable = Toast.makeText(getContext(), "La table des piéces métalliques est déja remplie",Toast.LENGTH_LONG);
statusMetalPiecesTable.show();
}
return true;
我正在编写代码以使用 excel 文件中的一些数据填充表格。你能帮我解决这个问题吗?非常感谢。
【问题讨论】: