我很想知道如何在片段中的ListView项旁边添加图像。
我之前在常规活动中做过这个,但是没有使用Fragment并使用String数组项。
感谢任何帮助,谢谢......
片段列表视图:
public class Fragment2 extends ListFragment{
String[] list_items;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View rootView = inflater.inflate(R.layout. fragments_layout2, container, false);
list_items = getResources().getStringArray(R.array.list);
setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, list_items));
return rootView;
}
}
Listview片段XML:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
数组列表:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">App_name</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string-array name="list">
<item>Absract</item>
<item>Animail</item>
<item>Anime</item>
<item>Artistic</item>
<item>Cartoon</item>
<item>Comics</item>
<item>Celeberity</item>
<item >Cars</item>
<item>Fantasy</item>
<item>Forest</item>
<item>Food</item>
</string-array>
</resources>