You see, I'm doing an exercise in which I have a TextView and a GridView with a series of elements taken from a vector. When I choose something from the GridView, it is copied into the TextView.
activity_main code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.pcx.celda.MainActivity">
<TextView
android:id="@+id/seleccion"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ABD8F9"
android:text="Nombre"
android:textColor="#000066" />
<GridView
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#328DF9"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:verticalSpacing="8dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
/>
</LinearLayout>
MainActivity Code:
package com.example.pcx.celda;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
public class MainActivity extends Activity implements AdapterView.OnItemClickListener{
public String[] provincias= {"Almería", "Cádiz", "Córdoba", "Granada", "Huelva", "Jaen", "Malaga", "Sevilla"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter adaptador=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,provincias);
GridView grid=findViewById(R.id.grid);
grid.setAdapter(adaptador);
grid.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id){
TextView selection= findViewById(R.id.seleccion);
selection.setText(provincias[position]);
}
}
But something goes wrong. When I look at examples, it seems that instead of "support_simple_spinner_dropdown_item" I should put a note to an xml file (in the example they call it "cell.xml"), but I have no idea where that file comes from.