我的代码有问题 我想在用户点击时发送数据 并在另一个活动中接收数据 例子
我想发送项目的位置,然后我去第二项活动
我想显示位置=描述字段
的表格表格我的代码
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getApplicationContext(),Details.class);
i.putExtra("id",position);
startActivity(i);
}
});
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
TextView t1=(TextView)findViewById(R.id.t1);
ImageButton im=(ImageButton)findViewById(R.id.im);
Intent data=getIntent();
String des=data.getStringExtra("id");
// myDbHelper.openDataBase();
Cursor curser= DBAdapter.myDataBase.rawQuery("SELECT * FROM sweet where id = '" + des + "'", null);
curser.moveToPosition(0);
while (!curser.isAfterLast()) {
t1.append(curser.getColumnIndex(0));
curser.close();
}
第二项活动
Intent data=getIntent();
int des=data.getIntExtra("id", 1);
//String s= String.valueOf(des);
//
// Cursor sq= myDbHelper.myDataBase.rawQuery("select * from sweet where description = '"+des+"')",null);
try {
//String query = "SELECT * FROM sweet WHERE " + des + " = name";
String query = "SELECT * FROM sweet WHERE " + des + " = name";
SQLiteDatabase database = myDbHelper.getReadableDatabase();
//Cursor sq = myDbHelper.myDataBase.rawQuery("select * from sweet", null);
Cursor cursor = database.rawQuery(query, null);
cursor.moveToFirst();
String description = cursor.getString(2);
t1.setText(description);
}
我的表
ID 名称 描述 这是3场
答案 0 :(得分:0)
Intent data=getIntent();
int des=data.getIntExtra("id", 1);
try {
SQLite database=myDBHelper.getWritableDatabase();
Cursor cursor = database.rawQuery(SELECT * FROM sweet WHERE desccription =? ", new String[]{String.valueOf(des)}, null);
Details details=new Details();
if(cursor !=null)
{
while(cursor.moveToNext())
{
String description = cursor.getString(cursor.getColumnIndexOrThrow(myDbHelper.Description));
details.setDescription(description);
t1.setText(description);
}
}
详情
public class Info {
private int id;
private String name;
private String description;
public void setID(int id)
{
this.id=id;
}
public int getID()
{
return this.id;
}
public String setName(String name)
{
this.name=name;
}
public String getName()
{
return this.name;
}
public String setDescription(String description)
{
this.description=description;
}
public String getDescription()
{
return this.description;
}