<item
android:id="@+id/menu_settings"
android:onClick="settingCount"
android:orderInCategory="99"
android:title="@string/menu_settings"
app:showAsAction="never" />
@gim0, @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridView = (GridView)findViewById(R.id.linear);
context=this;
createList(28);
buttonAdapter=new ButtonAdapter(this,R.layout.item,list);
gridView.setNumColumns(4);
gridView.setAdapter(buttonAdapter);
GridView.OnItemClickListener itemClickListener=new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
list.get(position).setBackgroundResource(R.drawable.but);
Log.e("Dfsdf",list.get(position).getText().toString());
buttonAdapter.notifyDataSetChanged();
}
};
gridView.setOnItemClickListener(itemClickListener);
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="neural_networks.bstu.com.myapplication.MainActivity">
<GridView
android:id="@+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp"></GridView>
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="neural_networks.bstu.com.myapplication.MainActivity">
<GridView
android:id="@+id/linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="0dp"
android:layout_marginLeft="0dp"
android:columnWidth="0dp"
android:paddingRight="0dp"
android:orientation="horizontal"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp"></GridView>
</android.support.constraint.ConstraintLayout>