I would like to list the data of my table but I do not get it. I do not know if my query is wrong, I have looked through all the forums and can not find anything
Class List
public class Lista extends AppCompatActivity {
ListView lv ;
ArrayList<String> lista;
ArrayAdapter adaptador;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lista);
lv = (ListView)findViewById(R.id.lista);
DbHelper db = new DbHelper(getApplicationContext(),null,null,1);
lista = db.llenar_lv();
adaptador = new ArrayAdapter(this, android.R.layout.simple_list_item_1,lista);
lv.setAdapter(adaptador);
}
}
DbHelper class
public void addUser(String usurarios, String password) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_usurarios, usurarios);
values.put(COLUMN_PASS, password);
long id = db.insert(USER_TABLE, null, values);
db.close();
Log.d(TAG, "Usuario insertado" + id);
}
public boolean getUser(String usurarios, String pass){
//HashMap<String, String> user = new HashMap<String, String>();
String selectQuery = "select * from " + USER_TABLE + " where " +
COLUMN_usurarios + " = " + "'"+usurarios+"'" + " and " + COLUMN_PASS + " = " + "'"+pass+"'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// Move to first row
cursor.moveToFirst();
if (cursor.getCount() > 0) {
return true;
}
cursor.close();
db.close();
return false;
}
public String eliminar(String usuarios){
String mensaje="";
SQLiteDatabase db= this.getWritableDatabase();
int cantidad = db.delete(USER_TABLE ,COLUMN_usurarios+"=?",new String[]{usuarios});
if(cantidad!=0){
mensaje="eliminado correctamente";
}else{
mensaje="No existe";
}
db.close();
return mensaje;
}
public ArrayList llenar_lv(){
ArrayList<String> lista = new ArrayList<>();
SQLiteDatabase db = this.getWritableDatabase();
String q = "SELECT * FROM users";
Cursor registros = db.rawQuery(q,null);
if(registros.moveToFirst()){
do{
lista.add(registros.getString(0));
}while(registros.moveToNext());
}
return lista;
}
}
And this is the layout
<?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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.techobbyist.signuplogin.LoginActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lista"
></ListView>
</LinearLayout>
LogCat
11-25 00:48:34.475 13742-13742/com.techobbyist.signuplogin W/IInputConnectionWrapper: getTextBeforeCursor on inactive
InputConnection 11-25 00: 48: 34.480 13742-13742 / com.techobbyist.signuplogin W / IInputConnectionWrapper: getCursorCapsMode on inactive InputConnection 11-25 00: 48: 34.585 13742-13742 / com.techobbyist.signuplogin W / IInputConnectionWrapper: getCursorCapsMode on inactive InputConnection 11-25 00: 48: 34.675 13742-13742 / com.techobbyist.signuplogin W / IInputConnectionWrapper: getSelectedText on inactive InputConnection 11-25 00: 48: 34.680 13742-13742 / com.techobbyist.signuplogin W / IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection 11-25 00: 48: 34.680 13742-13742 / com.techobbyist.signuplogin W / IInputConnectionWrapper: getTextAfterCursor on inactive InputConnection