I have a question: can I use a inner class variable that is instantiated in a method in an another method?
public void onItemClick(AdapterView<?> a, android.view.View v, int position, long id) {
// TODO Auto-generated method stub
int diffInDays=0;
Object o = lv1.getItemAtPosition(position);
Masina m = (Masina) o;
Toast.makeText(MainActivity.this, "Selected :" + " " + m, Toast.LENGTH_LONG).show();
String data=((Masina) image_details.get(position)).getData_fabr();
Calendar c=Calendar.getInstance();
SimpleDateFormat df=new SimpleDateFormat("dd/MM/yyyy");
String currData=df.format(c.getTime());
try {
Date obj=df.parse(data);
Date obj2=df.parse(currData);
diffInDays = (int) ((obj2.getTime() - obj.getTime())/ (1000 * 60 * 60 * 24));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int years=diffInDays/365;
int days=diffInDays%365;
poz=position;
mar=((Masina) image_details.get(poz)).getMarca();
mod=((Masina) image_details.get(poz)).getModel();
nr=((Masina) image_details.get(poz)).getNr_inm();
date=((Masina) image_details.get(poz)).getData_fabr();
afisare.setText("Numar inmatriculare: "+((Masina) image_details.get(position)).getNr_inm());
afisare.append("\nVarsta masina: "+years+" ani "+days+" zile");
}
});
}
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
}
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch(item.getItemId()) {
case R.id.edit:
Toast.makeText(this, "Ai ales: " + getResources().getString(R.string.Editeaza), Toast.LENGTH_SHORT).show();
Intent startNewAct=new Intent(MainActivity.this, EditActivity.class);
startNewAct.putExtra("marca",mar);
startNewAct.putExtra("model",mod);
startNewAct.putExtra("Nr.inm",nr);
startNewAct.putExtra("Data",date);
startActivityForResult(startNewAct,0);
return true;
i want to use vb mar in method onContextItemSelected. Someone help, please. Thank you very much.