1

I am using the masterdetailsflow template to build a custom detail layout. it doesn't seem to work well. The closest question asked before does not seem to be solving my problem at ListView not showing up in fragment I put a Log to do debug, it seems to pass the "Check1" but it does not displaying.

public class RouteItemDetailFragment extends Fragment {
...
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_routeitem_detail, container, false);
        if (mItem != null) {
            ((TextView) rootView.findViewById(R.id.routeitem_detail)).setText(mItem.title);
             Log.i("GPS", "onCreateView - RouteItemDetailFragment - check listadapter");          
        }
        return rootView;
    }
    @Override
    public void onViewCreated (View view, Bundle savedInstanceState){
        ArrayList<String> listItems = new ArrayList<String>();
        listItems.add("helo1");
        listItems.add("helo2");
        listItems.add("helo3");
        listItems.add("helo4");
        ArrayAdapter<String> adapter;
            ((TextView) view.findViewById(R.id.txt1)).setText("kkkkkk");
            Log.i("Check1", "onCreateView - RouteItemDetailFragment - check listadapter");          
            adapter=new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_list_item_1,
                    listItems);
            adapter.notifyDataSetChanged();
            ListView listAdapter = (ListView) view.findViewById(R.id.lv);
            listAdapter.setAdapter(adapter);

    }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/twopanecontainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        style="?android:attr/textAppearanceLarge"
        android:id="@+id/routeitem_detail"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="16dp"
        tools:context=".RouteItemDetailFragment" />
    <TextView
        android:id="@+id/txt1"
        style="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="16dp"
        />
    <ListView
        android:id="@+id/lv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </ListView>

</LinearLayout>
Community
  • 1
  • 1
james
  • 37
  • 2
  • 10

1 Answers1

2

Your LinearLayout displays Views horizontally by default, so your second TextView and ListView are probably just being displayed off screen. Change the orientation to "vertical":

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/twopanecontainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
Sam
  • 86,580
  • 20
  • 181
  • 179
  • Okay you give me a very good clue. its not only the vertical orientation but also the the textview height is covering the whole screen. I have changed the xml file to the following and it solved my problem. Thanks bro. `code` – james Nov 18 '12 at 10:44
  • I wanted to post the whole xml code but it can't seem to take everything. I will just post part of the code.
    
    
    
    
    – james Nov 18 '12 at 11:04