ListView data parse and navigation
I have list of items. This items have details associated with them, in the database. I want to click on a item of the list and that navigate to a activity that shows the details of this items in a EditText. I already have the navigation part but i can't do the most important part that consist in show the details of the item 开发者_StackOverflowi clicked.
this is my method for navigation
edition.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
final String aux= (String) lt.getItemAtPosition(position);
Intent myIntent = new Intent(infoList.this, EditarLocais.class);
startActivity(myIntent);
}
});
Can somebody help?
thanks
do it in "Android Way"
use ContentProvider
public void onItemClick(AdapterView<?> l, View v, int position, long id) {
Intent itemIntent = new Intent(this, ItemActivity.class);
listIntent.setData(Uri.withAppendedPath("content://my.app.content/edition", Long.toString(id)));
startActivity(listIntent);
}
then in ItemActivity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.item_activity);
Intent intent = getIntent();
if (intent != null) {
Uri uri = intent.getData();
if (uri != null) {
Cursor cursor = managedQuery(uri, new String[] { "All", "Columns", "That" }, null, null, null);
Option #1:
The Application
class could be what you're looking for. There is a very good answer that explains how to use it and actually it is everything you need. You can find the answer here: Android: How to declare global variables?.
Option #2:
Use Intent.putExtra(...)
method to send further data from your previous Activity
to your next Activity
.
Option #3:
This is a dirty quick fix (not recommended). Declare your data object as static
and reach it by using YourActivity.mMyDataObject
.
精彩评论