Reputation:
I hava a Gallery Image, and I want to add a title below each item (image).
This is my actual adapter :
@Override
public View getView(int position, View inputView, final ViewGroup parent) {
ViewHolder holder;
EmergencyCall item = listEmergencyCall.get(position);
if (inputView == null) {
holder = new ViewHolder();
inputView = inflater.inflate(R.layout.gallery_item, null);
holder.imageView = (ImageView) inputView.findViewById(R.id.imageView);
holder.textView = (TextView) inputView.findViewById(R.id.titletxt);
inputView.setTag(holder);
} else {
holder = (ViewHolder) inputView.getTag();
}
holder.imageView.setImageResource(item.getImg());
holder.textView.setText(item.getTitle());
return inputView;
}
public static class ViewHolder {
public RelativeLayout backgroundLayout;
public ImageView imageView;
}
}
This is the xml file :
<RelativeLayout
android:id="@+id/background_layout"
android:layout_width="120dp"
android:layout_height="100dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/titletxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp" />
</RelativeLayout>
EIDT : this should be work now. Now titles are added to the Gallery image
Upvotes: 0
Views: 303
Reputation: 3114
use a TextView and ImageView in Relative Layout or FrameLayout like this :-
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/thumbHolder">
<com.views.RotatingGallery
android:id="@+id/emergency_call_gallery"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"/>
<TextView
android:id="@+id/item_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:textColor="@color/green"
android:textSize="20sp" />
</FrameLayout>
then in your getView() method of adapter you can inflate this xml and set the text(title) to textView .. it should work fine .. ping me if you get it working !!
this should work !!
Upvotes: 1