以下の私のコードの問題は、ペインが常にデフォルトで開かれることです。理由はわかりません。明らかに、デフォルトでペイン (子) が開かれることは望ましくありません。ユーザーが lv_schedule をクリックした場合にのみ、ペインが開きます。そのため、フラグメントがロードされたら、最初に実際にペインをスライドさせて lv_schedule を確認する必要があります。
これは XML です。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scheduledblocks_sliding_pane_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:id="@+id/ll_left_pane_scheduled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@+id/lv_schedule"
android:layout_width="1000dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_marginRight="0dp"
/>
</LinearLayout>
<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container_scheduledblocksslidingpanedetailview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp" />
これはJAVAファイルです:
public class Fragment_allScheduledBlocks extends Fragment implements
View.OnClickListener, OnItemClickListener {
private Handler handler;
private ActionBarHelper mActionBar;
private Thread thread = new Thread();
public Fragment_allScheduledBlocks() {
}
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mLogger.printToLog(Constants.LOG_ENTRY,
" onCreateView of Fragment_scheduled_blocks.java",
Constants.TAG_ALL);
v = inflater.inflate(R.layout.fragment_scheduled_blocks, container,
false);
mSlidingLayout = (SlidingPaneLayout) v
.findViewById(R.id.scheduledblocks_sliding_pane_layout);
mSlidingLayout.setPanelSlideListener(new SliderListenerSchBlocks());
mSlidingLayout.openPane();
lv_scheduled = (ListView) v.findViewById(R.id.lv_scheduled);
lv_scheduled.setOnItemClickListener(this);
mActionBar = createActionBarHelper();
mActionBar.init();
return v;
}
/**
* This panel slide listener updates the action bar accordingly for each
* panel state.
*/
private class SliderListenerSchBlocks extends
SlidingPaneLayout.SimplePanelSlideListener {
@Override
public void onPanelOpened(View panel) {
mActionBar.onPanelOpened();
Log.v(Constants.TAG, "in onPanelOPened inside SliderListener");
getActivity().setTitle("LISTVIEW BLOCKS");
mPrefs.printAllMySharedPrefs(getActivity().getApplicationContext());
}
@Override
public void onPanelClosed(View panel) {
mActionBar.onPanelClosed();
Log.v(Constants.TAG, "in onPanelClosed inside SliderListener");
mPrefs.printAllMySharedPrefs(getActivity().getApplicationContext());
}
@Override
public void onPanelSlide(View panel, float slideOffset) {
// TODO Auto-generated method stub
super.onPanelSlide(panel, slideOffset);
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
private class ActionBarHelper {
public void init() {
}
public void onPanelClosed() {
}
public void onPanelOpened() {
}
public void onFirstLayout() {
}
public void setTitle(CharSequence title) {
}
}
/*
* Create a compatible helper that will manipulate the action bar if
* available.
*/
private ActionBarHelper createActionBarHelper() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// return new ActionBarHelperICS();
return new ActionBarHelper();
} else {
return new ActionBarHelper();
}
}
}