Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good Day Developers, I already implement this fantastic library called "Android-PanesLibrary" by Kenrick Rilee. and what i want to achive is something like this.

http://stackoverflow.com/questions/28875064/android-paneslibrary-using-string-array[^]

This is MainActivity.java :
Java
public class MainActivity_ extends PanesActivity {

protected Fragment mainmenuFragment = null ;
protected Fragment submenu_1_Fragment = null ;
protected Fragment submenu_2_Fragment = null ;
protected Fragment details_Fragment = null ;

private class ExamplePaneSizer implements PanesSizer.PaneSizer {
    private static final int DEFAULT_PANE_TYPE = 0;
    private static final int LIST_VIEW_PANE_TYPE = 1;
    private static final int DETAILS_VIEW_PANE_TYPE = 2;
    private static final int UNKNOWN_PANE_TYPE = -1;

    @Override
    public int getWidth(int index, int type, int parentWidth, int parentHeight) {
        if (parentWidth > parentHeight) {
            if (type == DEFAULT_PANE_TYPE && index == 0)
                return (int) (0.25 * parentWidth);
            else if (type == DEFAULT_PANE_TYPE)
                return (int) (0.375 * parentWidth);
            else if (type == LIST_VIEW_PANE_TYPE)
                return (int) (0.375 * parentWidth);
            else if (type == DETAILS_VIEW_PANE_TYPE)
                return (int) (0.625 * parentWidth) ;
            else throw new IllegalStateException("Pane has unknown type");
        } else {
            if (type == DEFAULT_PANE_TYPE && index == 0)
                return (int) (0.4 * parentWidth);
            else if (type == DEFAULT_PANE_TYPE)
                return (int) (0.6 * parentWidth);
            else if (type == LIST_VIEW_PANE_TYPE)
                return (int) (0.6 * parentWidth);
            else if (type == DETAILS_VIEW_PANE_TYPE)
                return parentWidth ;
            //if (type == DEFAULT_PANE_TYPE)
                //return (int) (0.75 * parentWidth);
            else throw new IllegalStateException("Pane has unknown type");
        }
    }

    @Override
    public int getType(Object o) {
        if (o.getClass().getSimpleName().contains("List")) {
            return LIST_VIEW_PANE_TYPE;
        } else if (o.getClass().getSimpleName().contains("Detail")) {
            return DETAILS_VIEW_PANE_TYPE;
        }
            return DEFAULT_PANE_TYPE;
        //if (o instanceof ExampleFragment)
            //return DEFAULT_PANE_TYPE;
        //else return UNKNOWN_PANE_TYPE;
    }

    @Override
    public boolean getFocused(Object o) {
        return false;
    }
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setPaneSizer(new ExamplePaneSizer());

    // Lets setup a menu and a first pane!
    if (savedInstanceState == null) {

        mainmenuFragment = new MainMenuFragment();
        details_Fragment = new DetailsFragment();
        setMenuFragment(mainmenuFragment);
        addFragment(mainmenuFragment, details_Fragment);
    }
}

public void updateFragment(Fragment f) {
}
}


This is MainMenuFragment.java :
Java
public class MainMenuFragment extends android.app.ListFragment {

private static int sExampleNum = 0;
protected final String TAG = "mainmenuFragment" ;

@ViewById(R.id.menu_listview)
protected ListView menuListView ;
private View parentView;
int mCurCheckPosition = 0;

public MainMenuFragment() {
    super();
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Resources res = getResources();
    String [] mainmenulistview = res.getStringArray(R.array.listview_main_menu);
    ArrayAdapter<String> connectArrayToListView = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_activated_1,mainmenulistview);
    setListAdapter(connectArrayToListView);
    if (savedInstanceState != null) {
        mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
    }
    getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    showDetails(mCurCheckPosition);
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt("curChoice", mCurCheckPosition);
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    showDetails(position);
}

void showDetails(int index) {

    //mCurCheckPosition = index;
    //getListView().setItemChecked(index, true);
    //PCDesktopFragment_ pcDesktop = (PCDesktopFragment_) getFragmentManager().findFragmentById(R.id.sub_one_fragment);
    //if (pcDesktop == null || pcDesktop.getShownIndex() != index) {
    //    welder_pipe_reg = PCDesktopFragment_.newInstance(index);
    //    android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
    //    ft.replace(R.id.sub_one_fragment, pcDesktop);
    //    ft.commit();
    //}
}
}


the first problem is in showDetails Method. if i un-comment the code, it will give an error on line
getFragmentManager().findFragmentById(R.id.sub_one_fragment);


this is the second listview that need to be shown but can not because it wait until the first listview item need to be click

Java
public class PCDesktopFragment_ extends ListFragment {

View v;
public static int i;

public static PCDesktopFragment_ newInstance(int index){
    PCDesktopFragment_ f = new PCDesktopFragment_();
    Bundle args = new Bundle();
    args.putInt("index", index);
    index = i;
    f.setArguments(args);
    return f;
}

public int getShownIndex() {
    return getArguments().getInt("index", 0);
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    inflater.inflate(R.layout.sub_one_menu, container, false);
    return super.onCreateView(inflater, container, savedInstanceState);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (i == 0) {
        String [] sub_a = {"Test1","Test2"};
        setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, sub_a));
    }
}

//@ItemClick(R.id.sub_one_listview)
//protected void handleDomainClick(int position) {
//    Fragment f = null ;
//    if (position == 0) {
//        f = new PCDesktopFragment_();
//    }
//    Activity a = getActivity();
//    if (f != null && a != null && a instanceof FragmentLauncher)
//        ((FragmentLauncher) a).addFragment(this, f);
//}
}


Any ideas or help would be greatly appreciated. Environment : Windows 7, Android Studio, Genymotion.
Posted
Comments
Member 11428127 11-Mar-15 21:14pm    
is there somebody out there who can help ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900