Change your String Array to atleast look like this:
<string-array name="menu_array">
<item>
Page1 #ffffff
</item>
<item>
Page2 #ffffBB
</item>
<item>
Page3 #fff45f
</item>
<item>
Page4 #ffff00
</item>
</string-array>
I have tried to parse the string-array you specified,I obtained the result of the form:
Page1 #ffffff
This is,as far as I am concerned practically useless as you will have to still split your code using(where list is the actual string array):
String[] cmenu =list[i].split("#");
item.name=cmenu[0];
item.colour="#"+cmenu[1];
menuList.add(item);
Or you could use a subString method to do it.However I could not parse the colour value from your arrangement(always gave me a NumberFormatException) while the one I specifed seemed to work fine with:
int Color.parseColor(String color)
This is the code of the getView method of the custom adapter I created for the purpose of solving the problem:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row=convertView;
TextView textView;
if(row==null)
{
row=inflater.inflate(resourceId, parent, false);
textView=(TextView)row.findViewById(R.id.text1);
row.setTag(R.id.text1,textView);
}
else
textView=(TextView)row.getTag(R.id.text1);
textView.setText(menuList.get(position).name);
try{
Log.d(TAG, menuList.get(position).colour);
row.setBackgroundColor(Color.parseColor(menuList.get(position).colour));
}
catch(Exception ex)
{
Log.e(TAG, "Still does not work");
}
return row;
}
NOTE:item is an object of ColouredMenuItem which just wraps String name,colour
in a class.
The customAdapter has the constructor:
MadAdapter(Context context,List<ColouredMenuItem> list,int resourceId)
{
this.context=context;
this.menuList=list;
this.resourceId=resourceId;
inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
EDIT:You could also create an XML file that you could add to assets and parse it using any of the parsers available.