1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
public class DisplayMyCoProd extends Activity {
ArrayList<Locom> myList;
LocomAdpater dataAdapter;
ListView listView;
String pathFile;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.display_my_co_prod);
myList = new ArrayList<Locom>();
Intent intent = getIntent();
pathFile = intent.getStringExtra("EXTRA_pathFile");
TextView txtv = (TextView)findViewById(R.id.textView);
txtv.setText(pathFile);
dataAdapter = new LocomAdpater(this, myList);
listView = (ListView) findViewById(R.id.display_listview);
listView.setAdapter(dataAdapter);
listView.setOnItemClickListener(new ItemListView());
new MyTask().execute();
}
class MyTask extends AsyncTask<Void, Void, Void> {
ProgressDialog progressDialog;
private LocomAdpater adapter;
@Override
protected void onPreExecute() {
adapter = (LocomAdpater)listView.getAdapter();
progressDialog = ProgressDialog.show(DisplayMyCoProd.this, "Chargement en cours", "Veuillez patienter...", false, false);
}
@Override
protected Void doInBackground(Void... params) {
try {
AssetManager am = getAssets();
InputStream is = am.open(pathFile);
Workbook wb = Workbook.getWorkbook(is);
Sheet sheet = wb.getSheet(0);
int row = sheet.getRows();
int col = sheet.getColumns();
String xx = "";
for (int i = 13; i < row; i++) {
Locom locom;
locom = new Locom("Engin","Visite");
for (int c = 1; c < col; c++) {
Cell cell = sheet.getCell(c,i);
switch (c) {
case 1:
locom.setVisite(cell.getContents());
break;
case 2:
locom.setEngin(cell.getContents());
break;
default:
break;
}
xx = xx + cell.getContents();
}
myList.add(locom);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/* @Override
protected void onProgressUpdate(ArrayList<Locom>... values) {
adapter.add(values[0]);
count++;
setProgress((int)(((double))));
}*/
@Override
protected void onPostExecute(Void aVoid) {
progressDialog.dismiss();
Toast.makeText(DisplayMyCoProd.this,"Chargement réussi !", Toast.LENGTH_LONG).show();
}
}
private class ItemListView implements AdapterView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ViewGroup vg = (ViewGroup)view;
TextView tv_e = (TextView)vg.findViewById(R.id.tv_engin);
TextView tv_v = (TextView)vg.findViewById(R.id.tv_visite);
String engin = tv_e.getText().toString();
String visite = tv_v.getText().toString();
Toast.makeText(DisplayMyCoProd.this,engin +" : "+ visite, Toast.LENGTH_SHORT).show();
Intent ChoixDMCPActivity = new Intent(DisplayMyCoProd.this, ChoixDMCP.class);
ChoixDMCPActivity.putExtra("EXTRA_TV_E",engin);
ChoixDMCPActivity.putExtra("EXTRA_TV_V",visite);
startActivity(ChoixDMCPActivity);
}
}
} |
Partager