Trouble with 9.12


#1

Every time i launch the activity, it shows the wrong view. The fragment_crime.xml is what is displayed and not a list view

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.bignerdranch.android.criminalintent"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity android:name = "com.bignerdranch.android.criminalintent.CrimeListActivity">
        	<intent-filter>
        	    <action android:name="android.intent.action.MAIN" />
        	    <category android:name="android.intent.category.LAUNCHER"/>
        	</intent-filter>    
        </activity>
       <!-- <activity
            android:name="com.bignerdranch.android.criminalintent.CrimeActivity"
            android:label="@string/app_name" >
        </activity> --> 
    </application>

</manifest>
public class CrimesListFragment extends ListFragment {
	private ArrayList<Crime> mCrimes;
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		getActivity().setTitle(R.string.crimes_title);
		mCrimes = CrimeLab.get(getActivity()).getCrimes();
		ArrayAdapter<Crime> adapter = new ArrayAdapter<Crime>(getActivity(),android.R.layout.simple_list_item_1,mCrimes);
		setListAdapter(adapter);
	}
}

public class CrimeListActivity extends SingleFragmentActivity {

	@Override
	protected Fragment createFragment() {
		// TODO Auto-generated method stub
		return new CrimesListFragment();
	}

}

i am getting very frustrated by this


#2

What does your CrimeListActivity implementation look like? And what does SingleFragmentActivity look like?


#3
package com.bignerdRanch.android.criminalintent;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;

public abstract class SingleFragmentActivity extends FragmentActivity {
	
	protected abstract Fragment createFragment();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_fragment);
		FragmentManager fm = getSupportFragmentManager();
		Fragment fragment = fm.findFragmentById(R.id.fragmentContainer);
		if(fragment == null){
			fragment = new CrimeFragment();
			fm.beginTransaction().add(R.id.fragmentContainer, fragment).commit();
		}
	}

}

package com.bignerdRanch.android.criminalintent;

import android.support.v4.app.Fragment;

public class CrimeListActivity extends SingleFragmentActivity {

	@Override
	protected Fragment createFragment() {
		return new CrimeListFragment();
	}

}

Thanks in advance


#4

I think I was seeing the same issue, but I realized that I was editing the AndroidManifest.xml inside the bin folder. This is not the one you want to edit.