0

Since I am using chrisbanes push down to refresh library, I had to remove normal listview and replace it with the new one. After that though, long push on listview item doesn't work and always creashes. It seems that info returns always null, as he doesn't get information, what I am actually clicking, which is bad. Have been trying to fix it myself, but with no success.. Any help is appreciated.

xml layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >


<ProgressBar
    android:id="@+id/loadingbar"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:visibility="gone" />

<TextView
    android:id="@+id/loading_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="Loading... Hang in there!"
    android:visibility="gone" />

 <com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/animelist"
android:layout_height="fill_parent"
android:layout_width="fill_parent" />

and the longpush code:

/** This will be invoked when an item in the listview is long pressed */
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {

        Log.d("readInfo", "LONG CLICK!!"); 
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        Log.d("prereadlongclickinfo", "test"); 
        favorites = readFavoritesList();
        parsedFavorites = parse(favorites);
        Log.d("readlongclickinfo", "test2"); 
        Log.d("readlongclickinfo", "test: "); 

        /*boolean favorited = false;
        for(String favorite : parsedFavorites){
            if(favorite.equals(anime_list.get(info.position).seriaal)){
                menu.add(0, 2, 1, R.string.removeFavorite);
                favorited = true;
                break;
            }
        }
        if(!favorited) {
            menu.add(0, 1, 1, R.string.addFavorite);
            menu.add(0, 3, 1, R.string.addBlacklist);
        }*/
        menu.add(0, 4, 1, R.string.openWebpage);
        super.onCreateContextMenu(menu, v, menuInfo);
    }

Also, I am using custom adapter, where I store all the information regarding every listitem row item, which I need to use in longpush.

4

1 回答 1

5

可惜没有人帮忙。

好吧,经过数小时的研究,我找到了解决方案,这非常容易。我希望它能指导将来遇到同样问题的人。

基本上,我制作了空的 ListView 并给了它我 pushDownListView 所拥有的所有值。之后,我将其注册为创建功能。几行代码:

pullToRefreshView = (PullToRefreshListView) findViewById(R.id.animelist);
        ListView lv1 = pullToRefreshView.getRefreshableView();

    registerForContextMenu(lv1);

    lv1.setAdapter(anime_list_adapter);

    registerForContextMenu(lv1);
于 2013-05-19T16:20:45.733 回答