I'm trying to create a list with simple content, that is, each element is shown in a single line
ArrayList<String> list = new ArrayList<String>();
list.add("Simple Item1");
list.add("Simple Item2");
list.add("Simple Item3");
list.add("Simple Item4");
RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.simple_recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(new SimpleListAdapter(this,list));
draw_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:clickable="true"
android:background="?android:attr/selectableItemBackground">
<TextView
android:id="@+id/text1"
android:layout_marginLeft="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Example application"
android:textSize="16sp"
android:layout_gravity="center_vertical"
/>
</RelativeLayout>
Where I'm stuck in creating the SimpleListAdapter Adapter I have the following that does not work, I have taken it from another project and I am adapting it to work with a simple array.
public class SimpleListAdapter<T> extends ArrayAdapter<String> {
private final Activity context;
private final List<String> objects;
public static class ViewHolder {
public TextView text1;
}
public SimpleListAdapter(Context context, ArrayList<String> objects) {
super(context, 0, objects);
this.context = (Activity) context;
this.objects = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
//Obteniendo una instancia del inflater
LayoutInflater inflater = (LayoutInflater)getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Salvando la referencia del View de la fila
View listItemView = convertView;
//Comprobando si el View no existe
if (null == convertView) {
//Si no existe, entonces inflarlo con image_list_view.xml
listItemView = inflater.inflate(
android.R.layout.simple_list_item_1,
parent,
false);
}
//Obteniendo instancias de los elementos
TextView text1 = (TextView)listItemView.findViewById(android.R.id.text1);
//TextView subtitulo = (TextView)listItemView.findViewById(android.R.id.text2);
//Obteniendo instancia de la Tarea en la posición actual
//List<String> row = getItem(position);
//Devolver al ListView la fila creada
return listItemView;
}
}