ListView not populating, or WebView taking up entire screen?

时光毁灭记忆、已成空白 提交于 2019-12-13 01:22:29

问题


I have code that should populate my ListView in my UrlListFragment, but when I run it I see no effect. I put the problem aside to work on my WebView, and found that once I load a URL it uses the entire screen. I'm not sure if this means my ListView isn't being populated, so it doesn't take up space, so the WebView takes up the entire screen, or if the WebView is taking up the entire screen regardless of whether the ListView is being populated or not.

I populate my ListView like this:

    View returnView = inflator.inflate(R.layout.url_fragment, container, false);

    ListView listView1 = (ListView) returnView.findViewById(R.id.mylist);        
    String[] items = { "http://mobile.cs.fsu.edu/android", "http://www.google.com", "http://my-favoriate-website.com" };        
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, items);        
    listView1.setAdapter(adapter);

    return returnView;

And my main XML is this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</FrameLayout>

I place the Fragments in the main layout programattically like this:

    FragmentManager manager = getFragmentManager();
    FragmentTransaction trans = manager.beginTransaction();
    UrlListFragment urlfragment = new UrlListFragment();
    MyWebFragment webfragment = new MyWebFragment();
    trans.add(R.id.fragment_container, urlfragment, "my_url_fragment");
    trans.add(R.id.fragment_container, webfragment, "my_web_fragment");
    trans.commit();

What could the problem be such that my ListView just doesn't appear and my WebView takes up the entire screen?


回答1:


You should use this type of constructor

 ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)

where everything is the same as u wrote but in textViewResourceId you use android.R.id.text1



来源:https://stackoverflow.com/questions/12443312/listview-not-populating-or-webview-taking-up-entire-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!