For my master detail flow app I'm trying to inflate my Continents list view on my tablet but it won't do so and I end up with these errors in my log cat. Does anyone know what I'm doing wrong?
Continents List xml
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal" android:orientation="horizontal"
android:showDividers="middle" tools:context=".ItemListActivity">
<fragment android:id="@+id/continents_list" android:name="com.apptacularapps.md.ContinentsListFragment"
android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"
tools:layout="@android:layout/list_content" />
<FrameLayout android:id="@+id/item_detail_container" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_weight="3" />
</LinearLayout>
ContinentsListFragment.java
package com.apptacularapps.md;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ContinentsListFragment extends ListFragment {
private static final String STATE_ACTIVATED_POSITION = "activated_position";
private Callbacks mCallbacks = sContinentsCallbacks;
private int mActivatedPosition = ListView.INVALID_POSITION;
public interface Callbacks {
public void onItemSelected(String id);
}
private static Callbacks sContinentsCallbacks = new Callbacks() {
@Override
public void onItemSelected(String id) {
}
};
public ContinentsListFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO: replace with a real list adapter.
setListAdapter(new ArrayAdapter<ContinentsContent.ContinentsItem>(
getActivity(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1,
ContinentsContent.ITEMS));
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (savedInstanceState != null
&& savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
}
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// Activities containing this fragment must implement its callbacks.
if (!(activity instanceof Callbacks)) {
throw new IllegalStateException("Activity must implement fragment's callbacks.");
}
mCallbacks = (Callbacks) activity;
}
@Override
public void onDetach() {
super.onDetach();
// Reset the active callbacks interface to the Continents implementation.
mCallbacks = sContinentsCallbacks;
}
@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
mCallbacks.onItemSelected(ContinentsContent.ITEMS.get(position).id);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mActivatedPosition != ListView.INVALID_POSITION) {
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
}
}
public void setActivateOnItemClick(boolean activateOnItemClick) {
getListView().setChoiceMode(activateOnItemClick
? ListView.CHOICE_MODE_SINGLE
: ListView.CHOICE_MODE_NONE);
}
private void setActivatedPosition(int position) {
if (position == ListView.INVALID_POSITION) {
getListView().setItemChecked(mActivatedPosition, false);
} else {
getListView().setItemChecked(position, true);
}
mActivatedPosition = position;
}
}
Logcat
05-20 18:33:54.709 23134-23134/? E/libprocessgroup﹕ failed to make and chown /acct/uid_10056: Read-only file system
05-20 18:33:54.709 23134-23134/? W/Zygote﹕ createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
05-20 18:33:54.710 23134-23134/? I/art﹕ Not late-enabling -Xcheck:jni (already on)
05-20 18:33:55.254 23134-23147/com.apptacularapps.md I/art﹕ Background sticky concurrent mark sweep GC freed 3119(263KB) AllocSpace objects, 0(0B) LOS objects, 27% free, 825KB/1135KB, paused 18.552ms total 137.540ms
05-20 18:33:55.333 23134-23162/com.apptacularapps.md D/OpenGLRenderer﹕ Render dirty regions requested: true
05-20 18:33:55.340 23134-23134/com.apptacularapps.md D/﹕ HostConnection::get() New Host Connection established 0xa6933490, tid 23134
05-20 18:33:55.351 23134-23134/com.apptacularapps.md D/Atlas﹕ Validating map...
05-20 18:33:55.408 23134-23162/com.apptacularapps.md D/﹕ HostConnection::get() New Host Connection established 0xa6933af0, tid 23162
05-20 18:33:55.425 23134-23162/com.apptacularapps.md I/OpenGLRenderer﹕ Initialized EGL, version 1.4
05-20 18:33:55.440 23134-23162/com.apptacularapps.md D/OpenGLRenderer﹕ Enabling debug mode 0
05-20 18:33:55.472 23134-23162/com.apptacularapps.md W/EGL_emulation﹕ eglSurfaceAttrib not implemented
05-20 18:33:55.472 23134-23162/com.apptacularapps.md W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa6988180, error=EGL_SUCCESS
05-20 18:33:56.547 23134-23134/com.apptacularapps.md D/AndroidRuntime﹕ Shutting down VM
05-20 18:33:56.548 23134-23134/com.apptacularapps.md E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.apptacularapps.md, PID: 23134
java.lang.IllegalStateException: Activity must implement fragment's callbacks.
at com.apptacularapps.md.ContinentsListFragment.onAttach(ContinentsListFragment.java:90)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:907)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Aucun commentaire:
Enregistrer un commentaire