Android – oncreateview does not use fragment call in viewpager

I'm using the viewpager in the ACL to display several fragments. First, all listfragments of these fragments contain a list. I'm trying to imitate the 2 list, so each element in the list contains a list of the other two objects. I hope each cell can be long pressed (not the whole list item), so I implemented my own columnlayout (maybe it should be called celllayout) Each list item contains two long ColumnLayouts and getContextMenuInfo () to return information about which entity is pressed. This method looks for ViewPager, requests the current fragment, and then calls the fragment to return entity ID. from the long time clicked view, in order to get the correct line that the fragment needs to execute.

getListView().getPositionForView(v)

This is where the problem begins. Sometimes getlistview() throws an IllegalStateException saying "the content view has not been created". That is, oncreateview (...) has not been called. This sometimes happens only when the application recovers. Today, I tried to enable "do not keep activity" in "Settings" Option to recreate the problem. The developer option on my Galaxy nexus. I start the application, press home, and then reopen the application from the recent application menu. Now, if I long press any cell in listview, this exception will be thrown. Through some debugging output, I try to verify that oncreateview has never been called. This is a little strange, Because the entire viewpager and its fragment and its listview and its cell items are drawn!

I was told on #android dev that the listfragment in ACL does not support custom layout, so I re implemented my android.support.v4.app.fragment instead of using listfragment, but it didn't help

Short summary: I have a custom layout to handle long press layout events. The purpose is to create a menuinfo object, which contains information about the permissions in the pressed cells. In order to find the entities contained in the layout, I will eventually call listview.getpositionforview (view v), sometimes resulting in IllegalStateException

Here is my custom layout (there may be an easier way to get the viewpager instead of mining in the view hierarchy):

package org.remotestick;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View;
import android.widget.LinearLayout;

public class ColumnLayout extends LinearLayout {

    public ColumnLayout(Context context,AttributeSet attrs) {
        super(context,attrs);
    }

    public ColumnLayout(Context context) {
        super(context);
    }

    @Override
    protected ContextMenuInfo getContextMenuInfo() {
        int itemTypeId = getChildAt(0).getId();
        int positionTypeId = getId();
        View currentView = this;
        ViewPager viewPager = null;
        while(currentView.getParent() != null) {
            currentView = (View) currentView.getParent();
            if(currentView.getId() == R.id.pager) {
                viewPager = (ViewPager) currentView;
                break;
            } else if (currentView.getId() == R.id.rootLayout)
                break;
        }
        if(viewPager == null)
            return null;

        WorkspaceAdapter adapter = (WorkspaceAdapter) viewPager.getAdapter();
        Pair
  

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>