The idea is that with a grindview put the letters of the alphabet should be
A B C
D E F
G H I
But I put it all in one column. He left you the code
public class MainActivity extends AppCompatActivity {
private GridView gridView;
private TextView tv1;
static final String[] letras = new String[] { "A", "B", "C", "D", "E", "F",
"G", "H", "I", "J", "K", "L", "M", "N", "Ñ", "O", "P", "Q", "R",
"S","T", "U", "V", "W", "X", "Y", "Z" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = findViewById(R.id.gw1);
tv1 = findViewById(R.id.tv1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, letras);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
String resultado = (String) ((TextView) v).getText();
tv1.setText(resultado);
}
});
}
}
In the graphic part there is only the gridview and a textview
Actually it is not an error, define in your GridView the number of columns through the property
android:numColumns
:you can do it directly in the layout:
or programmatically using the method
setNumColumns(int numColumns)
thus: