I'm trying to write such a code : I have a string, and if string is "stack", I want to print s.gif, t.gif, a.gif, c.gif and k.gif. Here is the code that I wrote :
String myString = "stack";
for(int i = 0; i < myString.length(); i++)
{
String source= null;
if(myString .charAt(i) == 'a')
{
source = "R.drawable.folder.a.gif";
}
else if (myString .charAt(i) == 'b')
{
source = "R.drawable.folder.b.gif";
}
...//it goes until z
LinearLayout linearLayout= new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setLayoutParams(new AbsListView.LayoutParams(
AbsListView.LayoutParams.MATCH_PARENT,
AbsListView.LayoutParams.MATCH_PARENT));
ImageView imageView = new ImageView(this);
imageView.setImageResource();// I don't know what to write here
imageView.setLayoutParams(new AbsListView.LayoutParams(
AbsListView.LayoutParams.MATCH_PARENT,
AbsListView.LayoutParams.WRAP_CONTENT));
linearLayout.addView(imageView);
setContentView(linearLayout);
}
What I'm trying to do is set source string and give it to the setImageResource(), but I failed. Can you tell me how to fix this code? Thanks.