android - How to set the background colour of individual gridview cells from another activity? -
this code given below want change background color of items in grid view activity.
main.xml
enter code here <gridview android:id="@+id/students_grid" android:layout_width="fill_parent" android:layout_height="fill_parent" android:numcolumns="6" android:gravity="center" android:stretchmode="columnwidth"> </gridview>
main.java
gridview gridview = (gridview) findviewbyid(r.id.students_grid); arrayadapter<string> adapter = new arrayadapter<string>(this, android.r.layout.simple_list_item_1, student_array); gridview.setadapter(adapter); ..... public void changegriditemcolor(int position){ view view = gridview.getchildat(position); view.setbackgroundcolor(color.red); }
anotheractvity.java
..... new main().changegriditemcolor(index); .....
i done getting error call gridview.getchildat(position) on null object i.e. nullpointerexception.. send solution on this. thanks.
Comments
Post a Comment