Make FramementLayout demo better... and, um actually work.
Also some other small cleanup. Change-Id: Iaaf5d4a85113b4a01a4bd3986e2334972e1096ad
This commit is contained in:
@@ -26,8 +26,8 @@
|
||||
android:id="@+id/titles" android:layout_weight="1"
|
||||
android:layout_width="0px" android:layout_height="match_parent" />
|
||||
|
||||
<fragment class="com.example.android.apis.app.FragmentLayout$DialogFragment"
|
||||
android:id="@+id/dialog" android:layout_weight="1"
|
||||
<fragment class="com.example.android.apis.app.FragmentLayout$DetailsFragment"
|
||||
android:id="@+id/details" android:layout_weight="1"
|
||||
android:layout_width="0px" android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
<!-- BEGIN_INCLUDE(layout) -->
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent" android:layout_height="match_parent">
|
||||
<fragment
|
||||
class="com.example.android.apis.app.FragmentLayout$TitlesFragment"
|
||||
<fragment class="com.example.android.apis.app.FragmentLayout$TitlesFragment"
|
||||
android:id="@+id/titles"
|
||||
android:layout_width="match_parent" android:layout_height="match_parent" />
|
||||
</FrameLayout>
|
||||
|
||||
@@ -26,10 +26,10 @@ import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ScrollView;
|
||||
@@ -82,29 +82,52 @@ public class FragmentLayout extends Activity {
|
||||
|
||||
//BEGIN_INCLUDE(titles)
|
||||
public static class TitlesFragment extends ListFragment {
|
||||
DetailsFragment mDetails;
|
||||
int mCurCheckPosition = 0;
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
// Populate list with our static array of titles.
|
||||
setListAdapter(new ArrayAdapter<String>(getActivity(),
|
||||
android.R.layout.simple_list_item_1, Shakespeare.TITLES));
|
||||
android.R.layout.simple_list_item_activated_1, Shakespeare.TITLES));
|
||||
|
||||
// Restore last state for checked position.
|
||||
if (savedInstanceState != null) {
|
||||
mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
|
||||
}
|
||||
|
||||
// If we are showing details in the screen, set up the list to highlight.
|
||||
mDetails = (DetailsFragment)getFragmentManager().findFragmentById(R.id.details);
|
||||
if (mDetails != null && mDetails.isInLayout()) {
|
||||
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
|
||||
getListView().setItemChecked(mCurCheckPosition, true);
|
||||
mDetails.setText(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) {
|
||||
DetailsFragment frag = (DetailsFragment)
|
||||
getFragmentManager().findFragmentById(R.id.dialog);
|
||||
if (frag != null && frag.isVisible()) {
|
||||
mCurCheckPosition = position;
|
||||
|
||||
if (mDetails != null && mDetails.isVisible()) {
|
||||
// If the activity has a fragment to display the dialog,
|
||||
// point it to what the user has selected.
|
||||
frag.setText((int)id);
|
||||
mDetails.setText(position);
|
||||
getListView().setItemChecked(position, true);
|
||||
} else {
|
||||
// Otherwise we need to launch a new activity to display
|
||||
// the dialog fragment with selected text.
|
||||
Intent intent = new Intent();
|
||||
intent.setClass(getActivity(), DetailsActivity.class);
|
||||
intent.putExtra("text", (int)id);
|
||||
intent.putExtra("text", position);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -142,8 +165,13 @@ public class FragmentLayout extends Activity {
|
||||
Bundle savedInstanceState) {
|
||||
ScrollView scroller = new ScrollView(getActivity());
|
||||
mText = new TextView(getActivity());
|
||||
int padding = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
|
||||
4, getActivity().getResources().getDisplayMetrics());
|
||||
mText.setPadding(padding, padding, padding, padding);
|
||||
scroller.addView(mText);
|
||||
setText(mDisplayedText);
|
||||
if (mDisplayedText >= 0) {
|
||||
mText.setText(Shakespeare.DIALOGUE[mDisplayedText]);
|
||||
}
|
||||
return scroller;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +63,7 @@ public class FragmentRetainInstance extends Activity {
|
||||
Button button = (Button)v.findViewById(R.id.restart);
|
||||
button.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
if (mWorkFragment != null) {
|
||||
mWorkFragment.restart();
|
||||
}
|
||||
mWorkFragment.restart();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* This demo illustrates the use of CHOICE_MODE_MULTIPLE_MODAL, a.k.a. selection mode on ListView
|
||||
* couple with the new simple_selectable_list_item which uses a highligted border for selected items.
|
||||
* couple with the new simple_list_item_activated_1 which uses a highlighted border for selected
|
||||
* items.
|
||||
*/
|
||||
public class List16 extends ListActivity {
|
||||
@Override
|
||||
@@ -39,7 +40,7 @@ public class List16 extends ListActivity {
|
||||
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
|
||||
lv.setMultiChoiceModeListener(new ModeCallback());
|
||||
setListAdapter(new ArrayAdapter<String>(this,
|
||||
android.R.layout.simple_selectable_list_item, mStrings));
|
||||
android.R.layout.simple_list_item_activated_1, mStrings));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user