1
我使用masterdetailsflow模板来构建自定义的详细布局。它似乎不能很好地工作。最近问的问题似乎没有解决我的问题在 ListView not showing up in fragment 我把日志做调试,它似乎通过“检查1”,但它不显示。Listview不显示在masterdetailsflow的片段中
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>
好的,你给我一个很好的线索。它不仅垂直方向,而且文本视图高度覆盖整个屏幕。我已将xml文件更改为以下内容,并解决了我的问题。多谢兄弟。 'code' – james
我想发布整个XML代码,但它似乎无法承担一切。我只会发布部分代码。
– james