menuitem.getmenuinfo является нулевым в onContextItemSelected

У меня есть ScrollView со встроенным LinearLayout, как предлагается в ScrollView документация. Ниже приведено сокращение макета:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tab2_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/top"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    </LinearLayout>

</ScrollView>

Я использую следующий шаблон во многих видах деятельности, которые используют ListView вместо ScrollViewбез проблем. Таким образом, проблема кажется уникальной для ScrollView.

final ScrollView scrollView = (ScrollView) frame.findViewById(R.id.tab2_view); 
final LinearLayout layout = (LinearLayout) frame.findViewById(R.id.top); 

//load and sort backing ArrayList

//neither of these calls resolve the issue
registerForContextMenu(scrollView);
//registerForContextMenu(layout);

//load layout with views

Вот где возникает проблема. Значение, возвращаемое из item.getMenuInfo() всегда ноль.

@Override
    public boolean onContextItemSelected(MenuItem item){
        boolean result = false;
        try 
        {
            AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); //why is this null???
            switch (item.getItemId()) {
                //do stuff
            }
        }
        catch (Exception e) { ExceptionHandler.handleException(LOG_TAG, e); }
        return result;
    }

Кто-нибудь знает, как решить проблему?

Я нашел обходной путь в поддержании переменных состояния и проверке menuItemназвание вместо нуля AdapterContextMenuInfo, Но я бы предпочел понять, как получить AdapterContextMenuInfo из выбранного MenuItem,

Я прошел через SO сообщения. Все они, кажется, коренятся в ошибках копирования / вставки или не вызывают registerForContextMenu на правильный объект. Это единственная статья, которая предполагает, что есть проблема помимо этого.

0 ответов

Другие вопросы по тегам