I have created one gridview and use custom adapter for that. I added two images inside grid view.one is image and another one looks like close button (which is the same in all grid view items). the close button is set invisible in the beginning, i have another button in my activity, what i want is : when i click this button, i want to set the close button in every element of my grid view, but for now, when click on it, nothing happens.
below is my code :
ImageView deleteFavorImage;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.browser);
.....
GridView favorGrid = (GridView) findViewById(R.id.favorGrid);
favorGrid.setAdapter(adapter);
.....
View customView = findViewById(R.id.costumButton);
customView.setOnClickListener(this);
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.costumButton:
deleteFavorImage.setVisibility(View.VISIBLE);
break;
.....
}
This is my image adaptor code:
@Override
public View getView( int position, View convertView, ViewGroup parent)
{
View MyView = convertView;
final int pos=position;
LayoutInflater li = (LayoutInflater) MyContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
MyView = li.inflate(R.layout.favor_item, null);
ImageView iv = (ImageView) MyView.findViewById(R.id.favor_item_image);
iv.setImageResource(favorSites.get(pos));
deleteFavorImage = (ImageView) MyView.findViewById(R.id.favDelete);
deleteFavorImage.setImageResource(R.drawable.dubtndelete);
return MyView;
}
And finally this is my XML file code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="85dp"
android:layout_height="85dp"
android:orientation="vertical"
android:background="@drawable/dufavframe" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="75dp"
android:layout_height="75dp"
android:orientation="vertical"
android:layout_centerInParent="true"
android:gravity="center">
<com.test.favorsites.AspectRatioImageView android:layout_centerHorizontal="true"
android:id="@+id/favor_item_image"
android:layout_alignParentTop="true" android:layout_height="wrap_content"
android:layout_width="match_parent" android:adjustViewBounds="true"/>
</LinearLayout>
<ImageView android:id="@+id/favDelete" android:visibility="invisible"
android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginTop="-3dp"
android:layout_alignParentRight="true" android:layout_marginRight="-5dp">
</ImageView>
</RelativeLayout>
1 Answer