I'm currently trying to access and use an image in place of text in a Spinner I'm using. The below code works, if I were to use text specifically instead of drawables.
I previously referenced this question: Storing R.drawable IDs in XML array
Hoping to fix my problem, however I was unable to figure out exactly where I was going wrong. I seem to continuously get:
Error: No resource found that matches the given name (at '^index_1' with value '@drawable/ic_launcher.png')
Etc, for each image. Each drawable exists and is in the appropriate spot, the code is apparently beyond my 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 the .png extensions. I'm still receiving the same error, however. Any additional suggestions?
Also getting:
I got rid of those errors, I'm now getting:
\res\layout\activity_main.xml:12: error: Error: No resource found that matches the given name (at 'contentDescription' with value '@string/rate_main'). \res\layout\activity_main.xml:28: error: Error: No resource found that matches the given name (at 'entries' with value '@array/category_array'). \res\layout\activity_main.xml:36: error: Error: No resource found that matches the given name (at 'entries' with value '@array/rating_array'). res\layout\activity_main.xml:46: error: Error: No resource found that matches the given name (at 'entries' with value '@array/descriptor_array'). res\menu\main.xml:3: error: Error: No resource found that matches the given name (at 'title' with value '@string/action_settings').
As errors, however when I remove these list files, I have no issue. Also, for some reason it's saying it's affecting my other arrays however "rating_array" is the only one that's not your 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 the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}