【发布时间】:2016-03-11 07:19:44
【问题描述】:
我在 Activity A 中有一个listView,所有数据都是从SQLite 检索的。现在我想在单击列表时将数据传递给另一个新活动。我怎样才能做到这一点?
活动 A
Activity A 中有两个列表,假设第一个列表被点击,我希望它传递数据给 B。
listViewUpdate.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> listView, View view,
int position, long id) {
// Get the cursor, positioned to the corresponding listview_item_row in the result set
Intent intent=new Intent(getActivity(),B.class);
startActivity(intent);
}
});
我的活动 B 的某些部分
public class Edit_Details extends AppCompatActivity {
EditText Description,TimeIn,TimeOut;
String description;
SeekBar seekBar;
TextView progressText;
int progress=0;
SQLiteDatabase database;
MyDatabaseHelper dbHelper;
Cursor cursor;
private com.example.project.myapplication.API.WorkDetailsAPI WD;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_details);
Project=(Spinner)findViewById(R.id.SpinnerProject);
final String ID=getIntent().getStringExtra("ID"); // should be position?
WD = new com.example.project.myapplication.API.WorkDetailsAPI(getApplication());
Description=(EditText)findViewById(R.id.editTextWorkDescription);
TimeIn=(EditText)findViewById(R.id.TimeIn);
TimeOut=(EditText)findViewById(R.id.TimeOut);
seekBar=(SeekBar)findViewById(R.id.seekBarPercentage);
progressText=(TextView)findViewById(R.id.textProgress);
progressText.setText("Covered:" + "" + seekBar.getProgress() + "/" + seekBar.getMax());
Log.e("ID", ID);
RetrieveDetails(ID); // how to get the position ?
}
public void RetrieveDetails(long ID)
{
final long id=ID;
database=dbHelper.getWritableDatabase();
cursor=database.rawQuery("SELECT SubContractors, NumberOfPerson, NumberOfHours FROM " + MyDatabaseHelper.TABLE_WORKFORCE+ " WHERE _id= ? ",
new String[]{String.valueOf(id)}, null);
Details d=new Details();
if(cursor!=null) {
while (cursor.moveToNext())
{
description=cursor.getString(cursor.getColumnIndexOrThrow(MyDatabaseHelper.WorkDescription));
d.setWorkDescription(description);
Description.setText(description); // display learn java on editText
}
}
}
}
我需要知道如何让新活动记住被点击的列表项,然后从 A 中提取所有信息并显示在新活动中。如果这有意义..谢谢!
例如。记住精益java并在B上展示
【问题讨论】:
-
查看传递给
onItemClick的最后一个参数 -
对不起,我不明白
-
换句话说参见
AdapterView.OnItemClickListener文档,尤其是idonItemClick的参数 -
我需要知道如何让新活动记住被点击的列表项,然后从 A 中提取所有信息并显示在新活动中。如果这有意义..谢谢!
-
所以通过额外的传递'id':
intent.putExtra(KEY_ID, id)
标签: android sqlite listview android-intent