got a few problem here and hoping that you could help me out.
Let me first clarify the situation:
I have a static array of Integer in which inside was a R.drawable.images. Codes are as follows
private Integer[] imageIDs = {
//R.drawable.medal_my_first_perxtamp,
R.drawable.medal..._gray,
R.drawable.medal_y...te_me_gray,
R.drawable.medal_t...ring_gray,
R.drawable.medal_gi...ray,
R.drawable.medal_a..._gray,
R.drawable.medal_se..gray,
R.drawable.medal_p...._gray,
R.drawable.medal_m..._gray,
R.drawable.medal_lo.._gray,
R.drawable.m..._gray,
R.drawable.med..,
R.drawable.med..on_gray
};
Now what I am trying to do is change the value of imageIDs based on a condition so now ive added this code on getview
sqlAdapter = new SQLiteAdapter(mContext);
sqlAdapter.openToRead();
List<Integer> imageIDList = Arrays.asList(imageIDs);
String query2="Select achievementID from achievementdata_tb where memberID = 101";
Cursor cursor2 =sqlAdapter.read(query2);
if (cursor2 != null && cursor2.moveToFirst()) {
while(cursor2.moveToNext()){
val =cursor2.getString(0);
int val2 = Integer.parseInt(val);
String returnDrawable = getDrawables(val);
int intReturnDrawable = Integer.parseInt(returnDrawable);
imageIDList.set(val2, intReturnDrawable);
}
}
Note that I am getting values from database(achievement_ID) and the values is (6,2,3)
So what I did is get the cursor’s item one by one and check it on a public void getDrawables consist of
public String getDrawables(String str){
if (str.equals("3")){
str= "R.drawable.med...g";
}
else if (str.equals("2")){
str= "R.drawable.med..._me";
}
else if (str.equals("6")){
str= "R.drawable.me...._up";
}
return str;
}
See that I want to change the value of array imageIDs (which is a drawable) to another drawable image.
I dont have any error so I use debugger and found out that I am getting an error on this part int intReturnDrawable = Integer.parseInt(returnDrawable);
I am new to andriod but i know some basic functionalities..
Could you help me solve this out?
You can’t because, the return type of
getDrawable()is String. And the String like"R.drawable.med...g"can’t parse toInteger.So change the implementation of
getDrawable()return properintvalue ..Instead do something like,