i'm trying access , use image in place of text in spinner i'm using. below code works, if use text instead of drawables.
i referenced question: storing r.drawable ids in xml array
hoping fix problem, unable figure out going wrong. seem continuously get:
error: no resource found matches given name (at '^index_1' value '@drawable/ic_launcher.png')
etc, each image. each drawable exists , in appropriate spot, code apparently beyond understanding.
<string-array name="rating_array"> <item>n/a</item> <item>@drawable/ic_launcher.png</item> <item>@drawable/smile.png</item> <item>@drawable/stale.png</item> <item>@drawable/sad.png</item> <item>@drawable/angry.png</item> </string-array>
[edit]
i have rid myself of .png extensions. i'm still receiving same error, however. additional suggestions?
also getting:
i got rid of errors, i'm getting:
\res\layout\activity_main.xml:12: error: error: no resource found matches given name (at 'contentdescription' value '@string/rate_main'). \res\layout\activity_main.xml:28: error: error: no resource found matches given name (at 'entries' value '@array/category_array'). \res\layout\activity_main.xml:36: error: error: no resource found matches given name (at 'entries' value '@array/rating_array'). res\layout\activity_main.xml:46: error: error: no resource found matches given name (at 'entries' value '@array/descriptor_array'). res\menu\main.xml:3: error: error: no resource found matches given name (at 'title' value '@string/action_settings').
as errors, when remove these list files, have no issue. also, reason it's saying it's affecting other arrays "rating_array" 1 that's not standard text list.
code in it's entirety concerning this:
string.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="rating_array"> <item>n/a</item> </string-array> <string-array name="descriptor_array"> <item>n/a</item> <item>price</item> <item>service</item> </string-array> <string-array name="category_array"> <item>n/a</item> <item>restaurants</item> <item>hotels</item> <item>theater</item> <item>shopping</item> </string-array> <string name="app_name">w!nk</string> <string name="action_settings">settings</string> <string name="rate_main">rate</string> </resources>
mainactivity.java
import android.app.activity; import android.os.bundle; import android.view.menu; import android.widget.spinner; public class mainactivity extends activity { private spinner spinbutton1, spinbutton2, spinbutton3; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } public void addlisteneronspinneritemselection(){ spinbutton1 = (spinner) findviewbyid(r.id.spinbutton1); spinbutton1.setonitemselectedlistener(new customonitemselectedlistener()); spinbutton2 = (spinner) findviewbyid(r.id.spinbutton2); spinbutton2.setonitemselectedlistener(new customonitemselectedlistener()); spinbutton3 = (spinner) findviewbyid(r.id.spinbutton3); spinbutton3.setonitemselectedlistener(new customonitemselectedlistener()); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } }
as in error :
error: no resource found matches given name (at '^index_1' value '@drawable/ic_launcher.png')
because passing drawable image extension(.png) drawable names in string-array
. need remove file extensions(.png) drawable names using in string-array
change as:
<string-array name="rating_array"> <item>n/a</item> <item>@drawable/ic_launcher</item> <item>@drawable/smile</item> <item>@drawable/stale</item> <item>@drawable/sad</item> <item>@drawable/angry</item> </string-array>
Comments
Post a Comment