我想要的是在 ListView 中写入所选项目。
公共类 MainActivity 扩展 ListActivity {
private BenzinCursorAdapter Adapter;
private BenzinDbLoader dbLoader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dbLoader = new BenzinDbLoader(getApplicationContext());
dbLoader.open();
Cursor c = dbLoader.fetchAll();
Adapter = new BenzinCursorAdapter(getApplicationContext(), c);
setListAdapter(Adapter);
getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent,
View v, int position, long id){
//Benzin selectedbenzin = (Benzin) parent.getSelectedItem();
Benzin selectedbenzin = (Benzin) getListAdapter().getItem(position);
Toast.makeText(MainActivity.this, selectedbenzin.getDate(), Toast.LENGTH_LONG).show();
}
});
registerForContextMenu(getListView());
}
ListView item 一个 Benzin 元素
public class Benzin {
private String Date;
private String Kmo;
private String Mkm;
private String Hl;
private String Mft;
private String Af;
private String Osszk;
public Benzin(String aDate, String aKmo, String aMkm, String aHl,
String aMft, String aAf, String aOsszk) {
Date = aDate;
Kmo = aKmo;
Mkm = aMkm;
Hl = aHl;
Mft = aMft;
Af = aAf;
Osszk = aOsszk;
}
public String getDate() {
return Date;
}
public String getKmo() {
return Kmo;
}
public String getMkm() {
return Mkm;
}
public String getHl() {
return Hl;
}
public String getMft() {
return Mft;
}
public String getAf() {
return Af;
}
public String getOsszk() {
return Osszk;
}
}
我想要的是在 ListView 中写入所选项目,但发生了这种情况
为什么会这样?
谢谢