SimpleAdapter 和 ContextMenu

发布于 2024-10-30 18:28:34 字数 1868 浏览 1 评论 0原文

我的 Droid 开发者朋友们大家好!我有一个问题已经困扰我有一段时间了。我希望有人能帮助我,这样我就可以继续学习。

我在将 ContextMenu 连接到 SimpleAdapter 时遇到问题。我已经进行了大量搜索,但找不到或“连接点”来解决这个问题。我没有对 simpleadapter 和 ContextMenu 做任何花哨的事情。

我的设置似乎是正确的,因为列表视图的 onListItemClick 返回我已加载到列表中的 ID,因此我知道一切都已正确设置。

这是一个扩展 ListActivity 的公共类

这是我到目前为止所拥有的...

我的 ROW.xml 列表在此处加载良好

...<ListView
android:id="@id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:drawSelectorOnTop="false"/>
<TextView
    android:id="@id/android:empty"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="No data"/>

SimpleAdapter 片段。这很好用。

 SimpleAdapter notes = new SimpleAdapter(
            this,
            resourceNames,
            R.layout.list_question_row,
            new String[] { "qid", "line1","line2", "img", "img2" },
            new int[] { R.id.question_id, R.id.text1, R.id.text2, R.id.img, R.id.img2 } );
    ;
    setListAdapter( notes );

这就是事情崩溃的地方。我似乎不知道如何将 setOnCreateContextMenuListener 连接到 SimpleAdapter / ListView。

此外,Eclipse 也没有获取 R.id.list。我尝试将布局 XML 的 ID 切换为 @android:id/list 但这似乎也不起作用。我似乎无法获取 ListView 列表的 ID 的引用。

    setOnCreateContextMenuListener(new OnCreateContextMenuListener(){
    @Override 
 public void onCreateContextMenu(ContextMenu menu, View v,  ContextMenuInfo menuInfo) {  
     if (v.getId()==R.id.list) {  
         AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;  
         menu.setHeaderTitle("Action Menu");  
         menu.add(0, MENU_EDIT, 0, "Edit");  
         menu.add(0, MENU_DELETE, 0,  "Delete");
    }  
 }; //end of onCreateContextMenu

我希望这是可以简单解决的问题!预先感谢您的所有帮助。

Hello my fellow Droid Developers! I have a problem that's been kicking my butt for a while now. I'm hoping someone can help me so I can move forward with the learn'n.

I'm having trouble connecting a ContextMenu to my SimpleAdapter. I've done extensive searches but cannot find or "connect the dots" to solve this problem. I'm not doing anything fancy with the simpleadapter nor the ContextMenu.

My setup seems correct because the listview's onListItemClick returns the ID I've loaded into the list so I know everything is properly setup.

This is a public class which extends ListActivity

Here's what i have so far...

My ROW.xml The list loads fine here

...<ListView
android:id="@id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:drawSelectorOnTop="false"/>
<TextView
    android:id="@id/android:empty"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:text="No data"/>

SimpleAdapter snippet. This works fine.

 SimpleAdapter notes = new SimpleAdapter(
            this,
            resourceNames,
            R.layout.list_question_row,
            new String[] { "qid", "line1","line2", "img", "img2" },
            new int[] { R.id.question_id, R.id.text1, R.id.text2, R.id.img, R.id.img2 } );
    ;
    setListAdapter( notes );

Here's where things break down. I can't seem to figure out how to hook up the setOnCreateContextMenuListener to the SimpleAdapter / ListView.

Also, the R.id.list is not being picked up by Eclipse. I've tried switching the layout XML's ID to @android:id/list but that didn't seem to work either. I can't seem to get a reference to the ID of the ListView list.

    setOnCreateContextMenuListener(new OnCreateContextMenuListener(){
    @Override 
 public void onCreateContextMenu(ContextMenu menu, View v,  ContextMenuInfo menuInfo) {  
     if (v.getId()==R.id.list) {  
         AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;  
         menu.setHeaderTitle("Action Menu");  
         menu.add(0, MENU_EDIT, 0, "Edit");  
         menu.add(0, MENU_DELETE, 0,  "Delete");
    }  
 }; //end of onCreateContextMenu

I hope this is something simple to solve! Thanks in advance for all your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

念﹏祤嫣 2024-11-06 18:28:34

尝试使用 android.R.id.list,而不是 R.id.list

Instead of R.id.list, try android.R.id.list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文