0

Good Day Developers,我已经实现了 Kenrick Rilee 的名为“Android-PanesLibrary”的奇妙库。我想要实现的是这样的。

在此处输入图像描述

但我最终这样做:

在此处输入图像描述

我的第一个问题是,如果在 showDetails 方法中删除注释符号,它将显示错误。但如果我将该方法设为空,它将像第二个图像一样运行。

我的目标是如何仅使用字符串数组数据来做到这一点?

任何想法或帮助将不胜感激。

环境:Windows 7、Android Studio、Genymotion。

这是 MainMenuFragment.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);
}

// if I un-comment on method bellow, it will result an error. 

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();
    //}
}
}

然后我已经创建了一个名为 PCDesktopFragment.java 的类,它扩展了 ListFragment(这应该使用 listfragment 显示在第二个片段上)

@EFragment(R.layout.sub_one_menu)
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);
//}
}
4

0 回答 0