How to apply different icons & different text in android grid view tutorial?

The two most important lines are these four: TextView tv = (TextView)v. FindViewById(R.id. Icon_text1); tv.

SetText("Profile "+position); ImageView iv = (ImageView)v. FindViewById(R.id. Icon_image1); if (position == 0) { iv.

SetImageResource(R.drawable. Bo_1); } else if (position == 1) { iv. SetImageResource(R.drawable.

Bo_2); } In the first line you get the TextView from the XMLlayout file. Afterwards you set the text of this TextView to "Profile " and a number. In third line your initializing the ImageView.

After that you're using the image called bo1 in that ImageView. So all you have to do is to add another text in the second line and change the image you're referring in the fourth line.

No It's Not working like the way you suggested. By implementing your logic i.e. , adding another text in the second line and changing the image reference in the fourth line it changes the image of all the 12 icons as I mentioned in the getcount method to the one I have referenced it.

Actually I want 12 different icons with 12 different text and if I add these four lines again it increases the no. Of icons and if I make the count to 1 then its fine but the icons are displaying vertically onlyn because of the linear layout in xml. Please help me out it's so urgent!

– user641366 Apr 23 at 16:30 By the way Thx for helping me out! – user641366 Apr 23 at 16:30 Ah you don't want just to change the image but various images... Then I would add a switch statement as I added in my answer. – Roflcoptr Apr 23 at 16:32 @Roflcoptr Can you Please elaborate your logic of using switch statement so that I can apply it to my code!

– user641366 Apr 23 at 16:38 @user641366 I edited my ansewr. – Roflcoptr Apr 23 at 16:39.

Try to use the following code public View getView(int position, View convertView, ViewGroup parent) { View v; ImageView iv = null; TextView tv = null; if(convertView==null){ LayoutInflater li = getLayoutInflater(); v = li. Inflate(R.layout. Grid_item, null); tv = (TextView)v.

FindViewById(R.id. Icon_text1); tv. SetText("Profile "+position); iv = (ImageView)v.

FindViewById(R.id. Icon_image1); } else { v = convertView; } iv. SetImageResource(imageIDsposition); return v; } Thanks Deepak.

Much, much, much better for ImageAdapter is: public class ImageAdapter extends BaseAdapter { private Context mContext; public ImageAdapter(Context c) { mContext = c; } public int getCount() { return mThumbIds. Length; } public Object getItem(int position) { return null; } public long getItemId(int position) { return 0; } // create a new ImageView for each item referenced by the Adapter public View getView(int position, View convertView, ViewGroup parent) { View v; if (convertView == null) { // if it's not recycled, initialize some attributes LayoutInflater li = getLayoutInflater(); v = li. Inflate(R.layout.

Grid_item, null); TextView tv = (TextView)v. FindViewById(R.id. Icon_text); tv.

SetText(mTextsIdsposition); ImageView iv = (ImageView)v. FindViewById(R.id. Icon_image); iv.

SetImageResource(mThumbIdsposition); } else { v = (View) convertView; } return v; } // references to our images private Integer mThumbIds = { R.drawable. Image1, R.drawable. Image2, R.drawable.

Image3, R.drawable. Image4 }; // references to our texts private String mTextsIds = { "Text 1", "Text 2", "Text 3", "Text 4" }; } Please, note that images and texts are in variables mThumbIds and mTextsIds The grid_item. Xml is.

TextView tv = (TextView)v. ImageView iv = (ImageView)v. Xml version="1.0" encoding="UTF-8"?

TextView tv = (TextView)v. ImageView iv = (ImageView)v. In the first line you get the TextView from the XMLlayout file.

Afterwards you set the text of this TextView to "Profile " and a number. In third line your initializing the ImageView. After that you're using the image called bo1 in that ImageView.

So all you have to do is to add another text in the second line and change the image you're referring in the fourth line. Tv = (TextView)v. Iv = (ImageView)v.

Not the answer you're looking for? Or ask your own question.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions