Note that there are some explanatory texts on larger screens.

plurals
  1. PONavigation drawer, ResourceNotFoundException
    primarykey
    data
    text
    <p>I would customize the navigation drawer. I used an example that I found on stackoverflow in an other thread. The code is a copy and paste, but when run the app in the logcat obtain an exception: "ResourceNotFoundException". Below paste a piece of logcat</p> <pre><code>08-02 20:06:26.367: E/AndroidRuntime(6084): android.content.res.Resources$NotFoundException: String resource ID #0x0 08-02 20:06:26.367: E/AndroidRuntime(6084): at android.content.res.Resources.getText(Resources.java:239) 08-02 20:06:26.367: E/AndroidRuntime(6084): at android.widget.TextView.setText(TextView.java:3837) 08-02 20:06:26.367: E/AndroidRuntime(6084): at it.ustation.DrawerAdapter.getView(DrawerAdapter.java:81) 08-02 20:06:26.367: E/AndroidRuntime(6084): at android.widget.AbsListView.obtainView(AbsListView.java:2177) .... </code></pre> <p>The code of my adapter is</p> <pre><code>public class DrawerAdapter extends ArrayAdapter&lt;ListNavigationItemModel&gt;{ public DrawerAdapter(Context context) { super(context, 0); } public void addHeader(int title) { add(new ListNavigationItemModel(title, -1, true)); } public void addItem(int title, int icon) { add(new ListNavigationItemModel(title, icon, false)); } public void addItem(ListNavigationItemModel itemModel) { add(itemModel); } @Override public int getViewTypeCount() { return 2; } @Override public int getItemViewType(int position) { return getItem(position).isHeader ? 0 : 1; } @Override public boolean isEnabled(int position) { return !getItem(position).isHeader; } public static class ViewHolder { public final TextView textHolder; public final ImageView imageHolder; public ViewHolder(TextView text1, ImageView image1) { this.textHolder = text1; this.imageHolder = image1; } } public View getView(int position, View convertView, ViewGroup parent) { ListNavigationItemModel item = getItem(position); ViewHolder holder = null; View view = convertView; if (view == null) { int layout = R.layout.list_item_drawer; if (item.isHeader) layout = R.layout.ns_menu_row_header; view = LayoutInflater.from(getContext()).inflate(layout, null); TextView text1 = (TextView) view.findViewById(R.id.nd_title); ImageView image1 = (ImageView) view.findViewById(R.id.nd_thumb_image); view.setTag(new ViewHolder(text1, image1)); } if (holder == null &amp;&amp; view != null) { Object tag = view.getTag(); if (tag instanceof ViewHolder) { holder = (ViewHolder) tag; } } if (item != null &amp;&amp; holder != null) { if (holder.textHolder != null) holder.textHolder.setText(item.title); if (holder.imageHolder != null) { if (item.iconRes &gt; 0) { holder.imageHolder.setVisibility(View.VISIBLE); holder.imageHolder.setImageResource(item.iconRes); } else { holder.imageHolder.setVisibility(View.GONE); } } } return view; } } </code></pre> <p>and the model is</p> <pre><code>public class ListNavigationItemModel { public int title; public int iconRes; public boolean isHeader; public ListNavigationItemModel(int title, int iconRes, boolean header) { this.title = title; this.iconRes = iconRes; this.isHeader = header; } public ListNavigationItemModel(int title, int iconRes) { this(title, iconRes, false); } } </code></pre> <p>and the xml</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="10dp" &gt; &lt;ImageView android:id="@+id/nd_thumb_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginRight="10dp" android:contentDescription="@string/thumbnail_desc" android:scaleType="fitCenter" android:src="@drawable/ic_save" /&gt; &lt;TextView android:id="@+id/nd_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toRightOf="@+id/nd_thumb_image" android:text="@string/c_desc" android:textColor="#fff" android:textSize="16sp" /&gt; </code></pre> <p></p> <p>and this is the code for add each item on adapter. mPlanetTitles is an array string.</p> <pre><code>for (String item : mPlanetTitles) { int id_menu_one = getResources().getIdentifier(item, "string", this.getPackageName()); int id_menu_one_icons = getResources().getIdentifier(menuOneIcons[oneIcons], "drawable", this.getPackageName()); ListNavigationItemModel mItem = new ListNavigationItemModel(id_menu_one, id_menu_one_icons); mAdapter.addItem(mItem); oneIcons++; } </code></pre>
    singulars
    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