I am new to android field. i am developing restaurant menu application, i have created list view which shows names of items in restaurant. when i select any one item in list view it will launch another activity, it contains text view field showing detail description of selected item. similarly when i select other items, it should launch same activity but data should be of that selected item, how to achieve this ? if i use sqlite database for data source.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You'll want to use the extras
Bundle
of anIntent
, e.g.Let's assume you have a
MenuListActivity
which shows the menu as list, and anMenuItemActivity
which shows a single menu item in more detail.In your
MenuListActivity.onListItemClick()
you want to pass the clicked menu item ID to yourMenuItemActivity
:In your
MenuItemActivity
you'll have a constant to identify the menu item (used above):You need to pass the values onItemClick:
If you want some data back from called Activity then you can use startActivityForResult() as:
In called activity you can set data as:
Note: Here you set the value in intent and pass it to setResult().
On returning back to calling Activity you can get data by overriding:
Note: You can pass primitive data type values thru Intent and if you want to pass other types then you have to use Bundle like this.
Receiving data in Activity:
Use intent extras to achieve this. You can transfer data to your activity by using intent.putExtra("KEY", VALUE). In the receiving activity you get the extras by calling getIntent().getExtras(); which returns a Bundle with the extras you've added in the calling activity.
Depends on what you are trying to achieve.Suppose you want to send the position of the list view item which is clicked then on click method send id to the activity with the intent
Similarly if you want to send data,have to work accordingly