0

行項目 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;
}

そのアイテムの情報を取得するにはどうすればよいですか?

そのアイテムの取得情報を数行教えてください

4

1 に答える 1

-1

以下のように、親から抽出する必要があります。ただし、ここには Android ワークスペースがないため、構文については 100% 確信が持てません。

 OIncome income = (OIncome) ((ListView) parent).getItemAtPosition(position);

これにより、Cast Exception をスローするコード行が置き換えられます。

OIncome income = list.get(position);
于 2013-11-08T14:25:46.820 に答える