Note that there are some explanatory texts on larger screens.

plurals
  1. POExpandable Listview with fragment
    text
    copied!<p>I got an issue while developing an app in android. I didn't find the solution after doing a lot of searches.</p> <p>An app having two fragment panels.First one, a <code>Fragment</code> showing the list of categories and sub categories where user can select a category or more specifically its sub category. Then its appropriate description will displayed on second fragment.</p> <p>I'm using an expandable <code>view</code> for the category list. But I got an error during run time. </p> <blockquote> <p>System service not available to activities before onCreate()</p> </blockquote> <p>Following are xml and code used in my app</p> <p><strong>activity_main_base.xml</strong></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" android:gravity="top" android:orientation="horizontal" tools:context=".MainBase" &gt; &lt;LinearLayout style="@style/FullscreenActionBarStyle" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="50dp"&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:id="@+id/categoryfragment" android:layout_width="fill_parent" android:layout_height="fill_parent" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>MainBase.java</strong></p> <pre><code>package my.newapp.x; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; public class MainBase extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_base); Fragment f=new Jobcat(); FragmentManager fm=getSupportFragmentManager(); FragmentTransaction ft=fm.beginTransaction(); ft.add(R.id.categoryfragment,f); ft.commit(); } } </code></pre> <p><strong>catlayout.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:scrollbars="vertical"&gt; &lt;ExpandableListView android:id="@+id/android:list" android:layout_width="match_parent" android:layout_height="wrap_content" android:childIndicatorRight="30dp" &gt; &lt;/ExpandableListView&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>jobcat.java</strong></p> <pre><code>package my.newapp.x; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class Jobcat extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v=inflater.inflate(R.layout.catlayout,container,false); return v; } @Override public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); try{ categoryfill j =new categoryfill(); j.fillme(); } catch(Exception e){ System.out.println("Errrr +++ " + e.getMessage()); } } } </code></pre> <p><strong>categoryfill.java</strong></p> <pre><code>package my.newapp.x; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.ExpandableListActivity; import android.widget.ExpandableListView; import android.widget.SimpleExpandableListAdapter; public class Jobcategoryfill extends ExpandableListActivity { private SimpleExpandableListAdapter listadapter; ExpandableListView expand; public void fillme() { List&lt;Map&lt;String,String&gt;&gt; category=new ArrayList&lt;Map&lt;String,String&gt;&gt;(); List&lt;List&lt;Map&lt;String, String&gt;&gt;&gt; subcategory=new ArrayList&lt;List&lt;Map&lt;String,String&gt;&gt;&gt;(); Map&lt;String,String&gt; cat1=new HashMap&lt;String, String&gt;(); cat1.put("Parent","A"); category.add(cat1); List&lt;Map&lt;String,String&gt;&gt; sublist1=new ArrayList&lt;Map&lt;String,String&gt;&gt;(); Map&lt;String,String&gt; sub11=new HashMap&lt;String, String&gt;(); sub11.put("child","a1"); sublist1.add(sub11); Map&lt;String,String&gt; sub12=new HashMap&lt;String, String&gt;(); sub12.put("child","a2"); sublist1.add(sub12); Map&lt;String,String&gt; sub13=new HashMap&lt;String, String&gt;(); sub13.put("child","a3"); sublist1.add(sub13); Map&lt;String,String&gt; sub14=new HashMap&lt;String, String&gt;(); sub14.put("child","a4"); sublist1.add(sub14); sublist1.add(sub115); subcategory.add(sublist1); listadapter=new SimpleExpandableListAdapter(this, category, R.layout.categoryparent, new String[] { "Parent" },new int[]{R.id.parentview}, subcategory, R.layout.categorychild, new String[]{"child"},new int[]{R.id.childview}); setListAdapter(listadapter); } } </code></pre> <p>I am unable to find the solution. Pleas anyone help me to resolve this issue or suggest me another method to implement this concept.</p>
 

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