[英]Onclick of Gridview button item, Text Color of button item should change
I am using custom adapter to set Gridview. 我正在使用自定义适配器来设置Gridview。 When I clicked on Button of GridView Item, another item gridview button also changes.
当我单击GridView Item的按钮时,另一个项目gridview按钮也会更改。 I have even added the layout for reference.
我什至添加了布局以供参考。 In the layout, there is two textView and one button.
在布局中,有两个textView和一个按钮。 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 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
<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: 我的问题的屏幕截图:
尝试将“ holder”与setTag和getTag一起使用。
I was getting that error because of scrolling inside gridview. 由于在gridview中滚动,因此出现了该错误。 It was affecting view of gridview.
它正在影响gridview的视图。 So i changed gridview to ExpandableHeightGridView and my problem is solved.
因此,我将gridview更改为ExpandableHeightGridView并解决了我的问题。 Thanks to people who invested time in solving My android problem.
感谢那些花时间解决我的android问题的人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.