Ich verwende einen benutzerdefinierten Adapter, um Gridview zu setzen. Wenn ich auf "Button of GridView Item" geklickt habe, ändert sich auch eine andere Element-Gridview-Schaltfläche. Ich habe sogar das Layout als Referenz hinzugefügt. Im Layout gibt es zwei TextView und eine Schaltfläche. Gibt es einen programmatischen Weg?Onclick des Gridview Knopfes, Text Farbe des Knopfes sollte sich ändern
@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>
Mein Grid
<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 von meinem Problem:
'v.setBackgroundColor (mcontext.getResources(). GetColor (R.color.green));' instance of 'setBackgroundColor (mcontext.getResources(). GetColor (R.color.green));' –
Versucht Aber hat nicht funktioniert @ GowthamanM –
ich will Button wie pro Anforderungen –