私はリストビューを作成し、データベースから膨らませました。そして、私は使用してonclicklistener
リストビューの項目を設定している:Android:リストビューのデータが別のアクティビティで渡されていません
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_books);
listView = (ListView) findViewById(R.id.listView);
call=(Button)findViewById(R.id.call);
userDbHelper = new UserDbHelper(getApplicationContext());
sqLiteDatabase = userDbHelper.getReadableDatabase();
cursor = userDbHelper.getInformation(sqLiteDatabase);
listDataAdapter = new ListDataAdapter(getApplicationContext(), R.layout.row_layout);
final TextView txt=(TextView) findViewById(R.id.pr);
listView.setAdapter(listDataAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent in=new Intent(Books.this,List1.class);
TextView txt=(TextView)findViewById(R.id.pr);
String getPrice=txt.getText().toString();
in.putExtra("getPrice",getPrice);
startActivity(in);
}
});
if (cursor.moveToFirst()) {
do {
id = cursor.getInt(0);
category = cursor.getString(1);
name = cursor.getString(2);
phone = cursor.getString(3);
price = cursor.getString(4);
desc = cursor.getString(5);
photo = cursor.getBlob(6);
//Bitmap bmp = BitmapFactory.decodeByteArray(photo, 0, photo.length);
DataProvider dataProvider = new DataProvider(id,category, name, phone, price, desc, photo);
listDataAdapter.add(dataProvider);
} while (cursor.moveToNext());
}
}
とList1.class
に私はそれに応じて他のレイアウトを膨らませることができるように、リストビュークリックされたデータベースからIDを取得しようとしています。どのようにそれを行うことができますか?
List1.class
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list1);
TextView txt=(TextView)findViewById(R.id.pr);
String getPrice=txt.getText().toString();
userDbHelper = new UserDbHelper(getApplicationContext());
sqLiteDatabase = userDbHelper.getReadableDatabase();
ImageView img1=(ImageView)findViewById(R.id.image2);
Intent in=getIntent();
Cursor cursor=userDbHelper.getContact(getPrice,sqLiteDatabase);
if(cursor.moveToFirst())
{
String NAME=cursor.getString(0);
String PHONE=cursor.getString(1);
String DESC=cursor.getString(2);
byte[] PHOTO=cursor.getBlob(3);
Bitmap bmp = BitmapFactory.decodeByteArray(photo, 0, photo.length);
img1.setImageBitmap(bmp);
}
userDbHelper=new UserDbHelper(getApplicationContext());
sqLiteDatabase=userDbHelper.getReadableDatabase();
price1=(TextView)findViewById(R.id.Price);
}
アクティビティを開始するときに 'onClickListener'に値を渡す必要があります。その値を取得してDBコードに渡します。私はあなたを正しく理解している。 – andre3wap
私はあなたの意図を始めている間にどこの値を渡しているのかわかりません。 – andre3wap
'intent.putExtra'も –