I am using custom adapter to set Gridview. When I clicked on Button of GridView Item, another item gridview button also changes. I have even added the layout for reference. In the layout, there is two textView and one button. Is there any Programmatical Way?
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
// TODO Auto-generated method stub
try {
if (convertView == null)
convertView = inflater.inflate(R.layout.appl_detail_grid_layout, null);
TextView appDSection = (TextView) convertView.findViewById(R.id.appD_gv_section);
final TextView appDdocty = (TextView) convertView.findViewById(R.id.appD_gv_doctyp);
final Button appDView=(Button)convertView.findViewById(R.id.appD_gv_view);`
AppDetailAttachment o = new AppDetailAttachment();
o = osList.get(position);
appDSection.setText(o.getSection());
appDdocty.setText(o.getDocTy());
appDView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.setBackgroundColor(mcontext.getResources().getColor(R.color.green));
// appDView.setTextColor(mcontext.getResources().getColor(R.color.green));
}
});
return convertView;
}
catch(Exception e){
throw e;
}
}
appl_detail_grid_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/appD_gv_section"
android:background="@color/white"
android:layout_marginTop="0dp"
android:layout_height="40dp"
android:layout_width="130dp"
android:layout_marginLeft="3dp"
android:textColor="@color/black"
/>
<TextView android:id="@+id/appD_gv_doctyp"
android:background="@color/white"
android:layout_marginTop="0dp"
android:layout_height="40dp"
android:layout_width="100dp"
android:layout_marginLeft="3dp"
android:textColor="@color/black"
/>
<Button
android:id="@+id/appD_gv_view"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_marginLeft="3dp"
android:gravity="center_horizontal"
android:textColor="@drawable/selector"
android:text="View"
android:background="@drawable/rectanglebutton"/>
</LinearLayout>
My GridView
<GridView
android:id="@+id/appD_gv"
android:layout_width="326dp"
android:layout_height="180dp"
android:layout_marginTop="42dp"
android:verticalSpacing="3dp"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:paddingRight="3dp"
android:gravity="center"
android:columnWidth="500dp"
android:horizontalSpacing="1dp"
android:numColumns="auto_fit"
android:fadeScrollbars="false"
android:scrollbarSize="3dp"
android:background="@color/indigo"
android:scrollbarThumbVertical="@color/check"
android:nestedScrollingEnabled="true"
android:stretchMode="columnWidth"/>
ScreenShot of My Problem:
I was getting that error because of scrolling inside gridview. It was affecting view of gridview. So i changed gridview to ExpandableHeightGridView and my problem is solved. Thanks to people who invested time in solving My android problem.