Note that there are some explanatory texts on larger screens.

plurals
  1. POListFragment with icon
    primarykey
    data
    text
    <p>i can manage to make a listfragment with same icon. but it seems i cant make that list with different icon. so the list result will be different icon for different item list. i try with it. and when i try to build it. it shows no error. but when i run it. its just force closes. here is my logcat. </p> <blockquote> <p>04-03 16:49:13.513: W/dalvikvm(9236): threadid=1: thread exiting with uncaught exception (group=0x40a71930)<br> 04-03 16:49:13.602: E/AndroidRuntime(9236): FATAL EXCEPTION: main<br> 04-03 16:49:13.602: E/AndroidRuntime(9236): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.surat.pendek/com.surat.pendek.utama}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'<br> 04-03 16:49:13.602: E/AndroidRuntime(9236): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)<br> 04-03 16:49:13.602: E/AndroidRuntime(9236): at android.os.Handler.dispatchMessage(Handler.java:99)<br> 04-03 16:49:13.602: E/AndroidRuntime(9236): at android.os.Looper.loop(Looper.java:137)<br> 04-03 16:49:13.602: E/AndroidRuntime(9236): at android.app.ActivityThread.main(ActivityThread.java:5041)<br> 04-03 16:49:13.602: E/AndroidRuntime(9236): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'' </p> </blockquote> <p>here is my sample fragment that extends listfragment, this fragment contain adapter too :</p> <pre><code>public class SampleListFragment extends ListFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.list, null); } public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); SampleAdapter adapter = new SampleAdapter(getActivity(), null); for (int i = 0; i &lt; 20; i++) { adapter.add(new SampleItem("Sample List", android.R.drawable.ic_menu_search)); } setListAdapter(adapter); } private class SampleItem { public String tag; public int iconRes; public SampleItem(String tag, int iconRes) { this.tag = tag; this.iconRes = iconRes; } } public class SampleAdapter extends ArrayAdapter&lt;SampleItem&gt; { private final Context context; private final String[] values; public SampleAdapter(Context context, String[] values) { super(context, R.layout.row); this.context = context; this.values = values; } public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(getContext()).inflate(R.layout.row, null); } ImageView icon = (ImageView) convertView.findViewById(R.id.row_icon); icon.setImageResource(getItem(position).iconRes); TextView title = (TextView) convertView.findViewById(R.id.row_title); title.setText(getItem(position).tag); String surat = title.getText().toString(); if (surat.equalsIgnoreCase("Huruf Hijaiyah")) { icon.setImageResource(R.drawable.aien); } else if (surat.equalsIgnoreCase("About")) { icon.setImageResource(R.drawable.alief); } else if (surat.equalsIgnoreCase("Surat+arti")) { icon.setImageResource(R.drawable.ba); } else if (surat.equalsIgnoreCase("Surat+latin")) { icon.setImageResource(R.drawable.emo_im_angel); } else { icon.setImageResource(R.drawable.emo_im_happy); } return convertView; } } </code></pre> <p>}</p> <p>and here is my fragment that extends listfragment :</p> <pre><code>public class MenuFragment extends ListFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.list, null); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); String[] surat = getResources().getStringArray(R.array.surat_pendek); ArrayAdapter&lt;String&gt; sampleAdapter = new ArrayAdapter&lt;String&gt;(getActivity(), R.layout.row, R.id.row_title, surat); setListAdapter(sampleAdapter); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload