I have a fragment compatibility issue in version 2.2. I use the Sherlock Action Bar to create an action bar, but I cannot create two fragments. I get this error all the time:
01-07 12:51:56.124: E/AndroidRuntime(475): FATAL EXCEPTION: main 01-07 12:51:56.124: E/AndroidRuntime(475): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pruebasherlock_v4/com.example.pruebasherlock_v4.MainActivity}: android.view.InflateException: Binary XML file line
My main_activity contains the following:
package com.example.pruebasherlock_v4; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
My main.xml contains the following:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <fragment android:id="@+id/listaIzq" android:layout_weight="1" android:layout_width="0dp" android:layout_height="fill_parent" class="com.example.pruebasherlock_v4.Lista"/> <fragment android:id="@+id/detallesDer" android:layout_weight="3" android:layout_width="0dp" android:layout_height="fill_parent" class="com.example.pruebasherlock_v4.Detalle" /> </LinearLayout>
And the class "lista" and "Detalle" contains the following:
Lista:
package com.example.pruebasherlock_v4; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import com.actionbarsherlock.app.SherlockListFragment; public class Lista extends SherlockListFragment{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override
Detalle:
package com.example.pruebasherlock_v4; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.actionbarsherlock.app.SherlockFragment; public class Detalle extends SherlockFragment { @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); Log.e("Test", "hello"); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.detalle, container, false); return view; } public void setText(String item) { TextView view = (TextView) getView().findViewById(R.id.textoDetalle); view.setText(item); } }
I feel a lot of code, but not because it is wrong.
Many thanks for your help.
source share