2012-09-15 53 views
1

我的代碼應該在我的UrlListFragment中填充我的ListView,但是當我運行它時,我看不到任何效果。 我把問題放在我的WebView上,發現一旦我加載一個URL,它就會使用整個屏幕。 我不確定這是否意味着我的ListView沒有被填充,所以它不佔用空間,所以WebView佔據了整個屏幕,或者如果WebView佔用了整個屏幕,而不管ListView正在填充或不填充。ListView未填充,或WebView佔用整個屏幕?

我填充我的ListView像這樣:

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; 

我的主XML是這樣的:

<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> 

我programattically放置片段在主要佈局是這樣的:

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(); 

問題是什麼,我的ListView不會出現,我的WebView佔據了整個屏幕?

回答

0

你應該使用這種類型構造的

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

這裏的一切是一樣的了你編寫但在textViewResourceId您使用android.R.id.text1