Note that there are some explanatory texts on larger screens.

plurals
  1. POAction Bar Sherlock + ListFragments + Fragments
    primarykey
    data
    text
    <p>I have a problem with the compatibility of the fragments in version 2.2. I use "Sherlock Action Bar" to create the actionbar, but I can not create two fragments. I get this error all the time:</p> <pre><code> 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 #7: Error inflating class fragment 01-07 12:51:56.124: E/AndroidRuntime(475): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.os.Handler.dispatchMessage(Handler.java:99) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.os.Looper.loop(Looper.java:123) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.app.ActivityThread.main(ActivityThread.java:4627) 01-07 12:51:56.124: E/AndroidRuntime(475): at java.lang.reflect.Method.invokeNative(Native Method) 01-07 12:51:56.124: E/AndroidRuntime(475): at java.lang.reflect.Method.invoke(Method.java:521) 01-07 12:51:56.124: E/AndroidRuntime(475): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 01-07 12:51:56.124: E/AndroidRuntime(475): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-07 12:51:56.124: E/AndroidRuntime(475): at dalvik.system.NativeStart.main(Native Method) 01-07 12:51:56.124: E/AndroidRuntime(475): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment 01-07 12:51:56.124: E/AndroidRuntime(475): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.view.LayoutInflater.inflate(LayoutInflater.java:407) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.view.LayoutInflater.inflate(LayoutInflater.java:320) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.view.LayoutInflater.inflate(LayoutInflater.java:276) 01-07 12:51:56.124: E/AndroidRuntime(475): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.app.Activity.setContentView(Activity.java:1647) 01-07 12:51:56.124: E/AndroidRuntime(475): at com.example.pruebasherlock_v4.MainActivity.onCreate(MainActivity.java:12) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 01-07 12:51:56.124: E/AndroidRuntime(475): ... 11 more 01-07 12:51:56.124: E/AndroidRuntime(475): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.pruebasherlock_v4-1.apk] 01-07 12:51:56.124: E/AndroidRuntime(475): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243) 01-07 12:51:56.124: E/AndroidRuntime(475): at java.lang.ClassLoader.loadClass(ClassLoader.java:573) 01-07 12:51:56.124: E/AndroidRuntime(475): at java.lang.ClassLoader.loadClass(ClassLoader.java:532) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.view.LayoutInflater.createView(LayoutInflater.java:466) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544) 01-07 12:51:56.124: E/AndroidRuntime(475): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66) 01-07 12:51:56.124: E/AndroidRuntime(475): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563) 01-07 12:51:56.124: E/AndroidRuntime(475): ... 20 more </code></pre> <p>My main_activity contains this:</p> <pre><code>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); } } </code></pre> <p>My main.xml contains this:</p> <pre><code>&lt;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" &gt; &lt;fragment android:id="@+id/listaIzq" android:layout_weight="1" android:layout_width="0dp" android:layout_height="fill_parent" class="com.example.pruebasherlock_v4.Lista"/&gt; &lt;fragment android:id="@+id/detallesDer" android:layout_weight="3" android:layout_width="0dp" android:layout_height="fill_parent" class="com.example.pruebasherlock_v4.Detalle" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>And the class "lista" and "Detalle" conteins this:</p> <p>Lista:</p> <pre><code>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 //se sobreescribe este método como el que siempre "carga" la información a mostrar en el fragment public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" }; ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this.getActivity(), android.R.layout.simple_list_item_1, values); setListAdapter(adapter); } @Override //al hacer tap en algun elemento de la vista, setea el texto del elemento en el nuevo fragment public void onListItemClick(ListView l, View v, int position, long id) { String item = (String) getListAdapter().getItem(position); Detalle fragment = (Detalle) getFragmentManager().findFragmentById(R.id.detallesDer); if (fragment != null &amp;&amp; fragment.isInLayout()) { fragment.setText(item); } else { /*Intent intent = new Intent(getActivity().getApplicationContext(), DetailActivity.class); intent.putExtra("value", item); startActivity(intent);*/ } } } </code></pre> <p>Detalle:</p> <pre><code>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); } } </code></pre> <p>I feel put much code, but not because it is wrong.</p> <p>Thank you very much for your help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload