如何为ListView的子项双击设置监听器?

时间:2015-09-30 19:42:01

标签: android listview listener

我无法找到这个听众。它存在吗? 例如,我将侦听器设置为单击一次:

ListView listCategories = (ListView) findViewById(R.id.listCategories);
ArrayAdapter<String> mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, titleCategories);
listCategories.setAdapter(mAdapter);
// Set listener:
listCategories.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id) {
    // cod...
    }
}

但是双击呢?

1 个答案:

答案 0 :(得分:0)

private void ListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    DependencyObject obj = (DependencyObject)e.OriginalSource;

    while (obj != null && obj != myListView)
    {
        if (obj.GetType() == typeof(ListViewItem))
        {
            // Do something here on double click
            MessageBox.Show("A ListViewItem was double clicked!");

            break;
        }
        obj = VisualTreeHelper.GetParent(obj);
    }
}

参考:Get the item doubleclick event of listview