码迷,mamicode.com
首页 > 其他好文 > 详细

ListView的使用(二)长按弹出上下文菜单

时间:2014-10-30 18:45:07      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   color   ar   使用   sp   文件   div   

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list);
        
        mDbHelper = new DiaryDbAdapter(this);
        mDbHelper.open();
        renderListView();
        ListView mylistView = getListView();
        mylistView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() {
            @Override
            public void onCreateContextMenu(ContextMenu menu, View v,
                    ContextMenuInfo menuInfo) {
                menu.setHeaderTitle("选择操作");
                menu.add(0, 0, 0, "更新该条");
                menu.add(0, 1, 0, "删除该条");
            }
        });    
    }
    

listview实现长按弹出上下文菜单。要注意

<ListView android:id="@+id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

中的id是@+id/android:list,这个并不在R文件中产生对应的id。故findViewById方法不可取。一个Activity中就只有一个ListView,所以setListAdapter(notes)方法并不需要指定对哪一个listview使用。

ListView mylistView = getListView();/*Get the activity‘s list view widget*/

ListView的使用(二)长按弹出上下文菜单

标签:android   style   blog   color   ar   使用   sp   文件   div   

原文地址:http://www.cnblogs.com/hixin/p/4063262.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!