我想获取信息对象在行项目ListView ..listview加载信息在数据库..
添加收入
public void addIncome(OIncome income) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(TABLE_INCOME_COLUMN_NAME, income.get_name());
values.put(TABLE_INCOME_COLUMN_CATEGORY, income.get_category() + 1);
values.put(TABLE_INCOME_COLUMN_AMOUNT, income.get_amount());
values.put(TABLE_INCOME_COLUMN_DATE, income.get_date());
values.put(TABLE_INCOME_COLUMN_TIME, income.get_time());
values.put(TABLE_INCOME_COLUMN_NOTE, income.get_note());
db.insert(TABLE_INCOME, null, values);
db.close();
}
获得收入
public List<OIncome> getIncome() {
List<OIncome> list = new ArrayList<OIncome>();
String selectIncome = "SELECT * FROM " + TABLE_INCOME + " INNER JOIN "
+ TABLE_CATEGORY + " ON " + TABLE_CATEGORY + "."
+ TABLE_CATEGORY_COLUMN_ID + "=" + TABLE_INCOME + "."
+ TABLE_INCOME_COLUMN_CATEGORY + " WHERE " + TABLE_INCOME + "."
+ TABLE_INCOME_COLUMN_DATE + "=" + "'" + GET_DATE + "'"
+ " ORDER BY " + TABLE_INCOME + "." + TABLE_INCOME_COLUMN_DATE
+ " DESC";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectIncome, null);
if (cursor.moveToFirst()) {
do {
OIncome income = new OIncome();
income.set_amount(cursor.getFloat(3));
income.set_category(cursor.getInt(8));
income.set_name(cursor.getString(1));
income.set_date(cursor.getString(4));
income.set_time(cursor.getString(5));
list.add(income);
} while (cursor.moveToNext());
}
return list;
}
ListIncomeAdapter类中的
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater inflater = context.getLayoutInflater();
convertView = inflater.inflate(layout, null);
}
OIncome income = list.get(position);
TextView tvnameincome = (TextView) convertView
.findViewById(R.id.tvnameincome);
TextView tvdateincome = (TextView) convertView
.findViewById(R.id.tvdateincome);
TextView tvtimeincome = (TextView) convertView
.findViewById(R.id.tvtimeincome);
TextView tvamountincome = (TextView) convertView
.findViewById(R.id.tvamountincome);
ImageView imglistincome = (ImageView) convertView
.findViewById(R.id.imglistincome);
Other other = new Other();
// OCatergory catergory = data.get(position);
tvnameincome.setText(income.get_name());
tvdateincome.setText(other.convertDateYear(income.get_date()));
tvtimeincome.setText(income.get_time());
tvamountincome.setText(income.get_amount() + "");
imglistincome.setImageResource(income.get_category());
return convertView;
}
如何获取该项目的信息..
请给我几行 获取有关该项目的信息答案 0 :(得分:-1)
您必须从父级中提取它,如下所示。我对语法并不是100%肯定,因为我这里没有Android工作区。
OIncome income = (OIncome) ((ListView) parent).getItemAtPosition(position);
这将替换您抛出Cast Exception的代码行:
OIncome income = list.get(position);