Advice needed with context menu

ⅰ亾dé卋堺 提交于 2020-01-11 14:05:04

问题


I have a XML layout which has two edit text fields, one for "title" and the the other for "story". When the user enters his data in these text fields and presses the back button the entry gets saved in a list view as the title set. The list view is present in an activity say A1. Now A1 extends Activity.

Whenever an item in the list is "long clicked" a context menu appears with edit, delete and read buttons. If the edit button is pressed I need to open another activity which can edit the data entered in the text fields corresponding to the item clicked. Also I'd be needing the id and the position of the item clicked in the list.

I am using list variable of type ListView to add my adapter. Also I am checking the edit, delete and read options of the context menu in the `public boolean onContextItemSelected(MenuItem item)' method.

How can I get the id and the position of the item clicked from here?


回答1:


in adapter you make a getter and setter of your item. When long click listener, put setter your item in there.

You should store your "title" and "story" in database and you can get it form database in a new activity




回答2:


I would think the best way to do this is to create an instance variable (declared after class definition and before onCreate) for the listview and assign the list view to it in onCreate(). Then you will be able to access the listview from your onContextItemSelected() method and pass them to your new activity

If you could post some of your code we should be able to help more.

I second Th0rndike's comments above. It is much easier to help someone if the question is readable and there is a good chance the answer will be accepted.



来源:https://stackoverflow.com/questions/10733802/advice-needed-with-context-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!