我試圖在片段中顯示listView,但是當我運行應用程序時,它會給出一個空白頁面而不是。我使用陣列適配器從片段中的字符串填充ListView。無法看到我的片段中的ListView
這裏是我的代碼:
public class CardContentFragment extends Fragment {
private String[] items;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater
.inflate(R.layout.item_card, container, false);
items = getActivity().getResources().getStringArray(R.array.list);
ListView lv = (ListView) view.findViewById(R.id.list);
ListAdapter myListAdapter = (new ArrayAdapter<String>(getActivity().getApplicationContext(),
android.R.layout.simple_list_item_1, list));
lv.setAdapter(myListAdapter);
return view;
}
}
array.xml
<string-array name="list">
<item>Argentina (54 11) 4863 3291</item>
<item>Aruba (297) 839 662</item>
<item>Australia (61 2) 9416 2373</item>
</string-array>
layout.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
</ListView>
</RelativeLayout>
有沒有錯誤,我認爲這只是一個佈局問題,但我無法解決。
顯示一個代碼,你如何在裏面附加fragment活動 – Rahul