Android Gallery with first thumbnail as coverpage?

You need to set the text in your textviews everytime and not only when you inflate the view.

Okay, thanks James for that info! – Sagar Hatekar Apr 13 at 21:49.

You should probably have 1 single layout file which holds the ui components in the gallery. Right now you have 2 TextView components which are independent of the Gallery. Instead, create some layout resource like this: gallery_item.

Xml So in your getView: View v = convertView; if(v == null) { LayoutInflater vi = (LayoutInflater)getSystemService(Context. LAYOUT_INFLATER_SERVICE); v = vi. Inflate(R.layout.

Gallery_item, null); holder = new ViewHolder(); holder. Text1 = (TextView)v. FindViewById(R.id.

TvTitle1); holder. Text2 = (TextView)v. FindViewById(R.id.

TvTitle2); holder. ImageView = (ImageView)v. FindViewById(R.id.

ImageView); v. SetTag(holder); } else holder = (ViewHolder)v.getTag(); if(position == 0) { holder. Text1.

SetVisibility(View. VISIBLE); holder. Text2.

SetVisibility(View. VISIBLE); holder.imageView. SetVisibility(View.

GONE); } else { holder. Text1. SetVisibility(View.

GONE); holder. Text2. SetVisibility(View.

GONE); holder.imageView. SetVisibility(View. VISIBLE); } return v; You may find that there is some strange behavior going on when you scroll through items, so you might have to directly access each UI component rather than using the holder: ((TextView)v.

FindViewById(R.id. TvTitle1)). SetVisibility(View.

GONE);, etc You also may be interested in setting different types of views for getView: http://developer.android.com/reference/android/widget/Adapter.html#getItemViewType(int).

Thanks for the info binnyb. But then what would I do in the setContentView() method of onCreate()? – Sagar Hatekar Apr 13 at 20:29 @binnyb - Also, where would I define the Gallery in xml file?

– Sagar Hatekar Apr 13 at 20:31 the layout to use in setContentView would be your main. Xml which includes your Gallery. You would also remove the 2 TextView objects from main.

Xml – binnyb Apr 13 at 20:42 @binnyb - Updated the code based on your changes but now I get an NPE on the line where it does a setVisibility() and seems like findViewById returns null. I did a project clean still this is the problem. Wonder what could be wrong.

Sorry for bothering you so much. – Sagar Hatekar Apr 13 at 21:48 does your gallery_item. Xml layout contain the TextView and ImageView components?

– binnyb Apr 13 at 21:53.

After trying all approaches suggested here, I wasn't able to still get a custom gallery the way I wanted it to. I kept running into ClassCastException. So, here's what worked for me till now.

This is just a workaround and incase someone comes up with a better way to design a custom gallery - do post your answer here so I can accept it. Thanks for helping out!

Called when the activity is first created. Gallery g = (Gallery) findViewById(R.main. This, "" + position, Toast.

MInflater = (LayoutInflater)getSystemService(Context.

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