Android: problems with CursorAdapter

92 views Asked by At

first of all thank you all for your answers and sorry for the bad English used, have a controller class to populate a listview and an adapter class that extends CursorAdapter, my problem is that when I setAdapter, my class adapter is not running the Newview method BindView certainly not running. Here is the code used for this, they hope can help. regards

public class ListaAdaptador extends CursorAdapter {


public static class ContenedorView
{
    TextView nombre;
    TextView apellidos;
    TextView dni;
    TextView telefono;
    ImageView img;
}
public ListaAdaptador(Context a, Cursor c)
{
    super(a, c);


}



@Override
public int getCount() {
    return 0;
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    LayoutInflater inflater =  (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.list_item,parent,false);
    ContenedorView contenedor = null;
    contenedor = new ContenedorView();
    contenedor.nombre = (TextView) view.findViewById(R.id.txt_item_nombre);
    contenedor.apellidos =(TextView) view.findViewById(R.id.txt_item_apellidos);
    contenedor.dni = (TextView) view.findViewById(R.id.txt_item_dni);
    contenedor.telefono = (TextView) view.findViewById(R.id.txt_item_telefono);
    contenedor.img = (ImageView) view.findViewById(R.id.ImageViewItem);
    view.setTag(contenedor);
    return view;
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
    ContenedorView contenedor = (ContenedorView) view.getTag();
    contenedor.nombre.setText(cursor.getString(cursor.getColumnIndex("nombre")));
    contenedor.apellidos.setText(cursor.getString(cursor.getColumnIndex("apellidos")));
    contenedor.dni.setText(cursor.getString(cursor.getColumnIndex("dni")));
    contenedor.telefono.setText(cursor.getString(cursor.getColumnIndex("telefono")));
    contenedor.img.setImageResource(R.drawable.img_nodisp);
}

}

clase ListaControlador

public class ListadoControlador extends ListActivity {

EditText aproximacion;
ListView lv;
ImageButton buscar;
SQLiteDatabase db;
Cursor cursor;
ListaAdaptador adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listado);
    aproximacion = (EditText) findViewById(R.id.EditText01);
    buscar =(ImageButton)findViewById(R.id.btnBuscar);
    lv=getListView();

    prepararBaseDeDatos();
    obtenemosValores();
}


public void prepararBaseDeDatos()
{
    AdminSQLiteOpenHelper admin = new AdminSQLiteOpenHelper(this,"registro",null,1);
    db = admin.getWritableDatabase();
}


public void obtenemosValores()
{
        cursor = db.rawQuery("select _id,nombre,apellidos,dni,telefono from paciente", null);
        adapter = new ListaAdaptador(ListadoControlador.this,cursor);
        lv.setAdapter(adapter);
  }
1

There are 1 answers

0
Bidhan On BEST ANSWER

Remove the three Override methods getCount(), getItem() and getItemId() from your ListaAdaptador class. You don't need them since you're using a CursorAdapter.