mardi 28 avril 2015

how to display data from a database into two Textview

i'am trying develop an application which save points and date in a database but, i want to show into a list the points in green and date in white. The points and the time points are above one another. My code: Class database public class BaseDeDatos extends SQLiteOpenHelper{

public BaseDeDatos(Context context) {
    super(context, "puntuaciones", null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE puntuaciones (puntos INTEGER,fecha VARCHAR)");

}
public void save(int points,String date){
     SQLiteDatabase db = getWritableDatabase();
     db.execSQL("INSERT INTO puntuaciones VALUES("+points+","+"'"+date+"')");
     db.close();
}
public Vector<String> listPoints(int cantidad) {
    Vector<String> result = new Vector<String>();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.rawQuery("SELECT puntos, fecha FROM " +
    "puntuaciones ORDER BY puntos DESC LIMIT " +cantidad, null);
    while (cursor.moveToNext()){
    result.add(cursor.getInt(0)+cursor.getString(1));
    }
    cursor.close();
    db.close();
    return result;
    }

and my class with the list

ListView lista;
BaseDeDatos bd;
Vector maxRegis;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maximos_registros);
    lista=(ListView)findViewById(R.id.lista);
    lista.setBackgroundColor(color.Aquamarine);
    maxRegis= new Vector();
    bd= new BaseDeDatos(this);
    maxRegis=bd.listaPuntos(10);
    ArrayAdapter adaptador= new ArrayAdapter(this,R.layout.elemento_lista,R.id.tv1,maxRegis);
    //MyAdapter adaptador= new MyAdapter(this,bd);
    lista.setAdapter(adaptador);
}

and the code of R.layout.elemento_lista

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight" >


<TextView
    android:id="@+id/tv1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="40dp"
    android:inputType="textCapCharacters"
    android:textColor="#FFD700"
    android:textStyle="bold"
    android:text="" />

<TextView
    android:id="@+id/tv2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/tv1"
    android:layout_alignParentBottom="true"
    android:textStyle="italic"
    android:text="" />

if i make a special adapter shows nothing, but with ArrayAdapter shows into the same TextView.

Aucun commentaire:

Enregistrer un commentaire