在我的适配器中,使id为putExtra,然后在活动详细信息中,我想获取id,并通过id获得数据库的信息。例如名称
MyRecyclerAdapter
holder.detalhes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(context, DetalhesPonto.class);
i.putExtra("id_detalhe", ponto1.getId());
context.startActivity(i);
}
});
}
数据库方法
public List<PontoDeInteresse> getPontoDeInteresseDetalhes(long id) {
List<PontoDeInteresse> data1 = new ArrayList<>();
SQLiteDatabase db1 = this.getWritableDatabase();
Cursor c1 = db1.rawQuery("SELECT * FROM " + TABLE_NAME_PONTO + " WHERE " + FIRST_COLUMN_PONTO + "= ?", new String[]{Long.toString(id)});
StringBuffer stringBuffer1 = new StringBuffer();
PontoDeInteresse ponto1 = null;
while (c1.moveToNext()) {
ponto1 = new PontoDeInteresse();
//int id = c1.getInt(c1.getColumnIndexOrThrow("id_ponto"));
String name = c1.getString(c1.getColumnIndexOrThrow("nome"));
String desc = c1.getString(c1.getColumnIndexOrThrow("descricao"));
String city = c1.getString(c1.getColumnIndexOrThrow("id_cidade"));
String latitude = c1.getString(c1.getColumnIndexOrThrow("latitude"));
String longitude = c1.getString(c1.getColumnIndexOrThrow("longitude"));
String rat = c1.getString(c1.getColumnIndexOrThrow("rating"));
String cate = c1.getString(c1.getColumnIndexOrThrow("id_categoria"));
//ponto1.setId(id);
ponto1.setNome(name);
ponto1.setDescricao(desc);
ponto1.setCidade(city);
ponto1.setLatitude(latitude);
ponto1.setLongitude(longitude);
ponto1.setRating(rat);
ponto1.setCategoria(cate);
stringBuffer1.append(ponto1);
// stringBuffer.append(dataModel);
data1.add(ponto1);
} return data1;
}