Sorry I have a problem wanting to add data to a database, actually the data seems to be entered but I can not show them in a list View, I would like to know what the problem is because the console does not throw any problems And neither mistakes nor anything here the following is the code:
package com.example.leaftime.rocketdefender;
/ ** * Created by Leaftime on 04/11/2017. * /
public class User { private Integer id; private String name; private Integer score;
public User(Integer id, String name, Integer score) { this.id = id; this.name = name; this.score = score; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getScore() { return score; } public void setScore(Integer score) { this.score = score; } }
- the above is the User () class that passes the data of my items
import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView;
import com.example.leaftime.rocketdefender.utils.utility;
import java.util.ArrayList;
public class HighscoreListActivity extends AppCompatActivity { ListView highscoreList;
ArrayList<String> listInfo; ArrayList<User> listUsers; ConectionSQLiteHelper conn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_highscore_list); conn = new ConectionSQLiteHelper(getApplicationContext(), "bd users", null, 1); highscoreList = (ListView) findViewById(R.id.highscoreList); getListPersons(); ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, listInfo); highscoreList.setAdapter(adapter); } private void getListPersons() { SQLiteDatabase db = conn.getReadableDatabase(); User user; listUsers = new ArrayList<User>(); //select * from users Cursor cursor = db.rawQuery("SELECT * FROM " + utility.TABLE_USER, null); while(cursor.moveToNext()) { user = new User(cursor.getInt(0),cursor.getString(1), cursor.getInt(2)); listUsers.add(user); } obtainList(); } private void obtainList() { listInfo = new ArrayList<String>(); for (int i = 0; i < listUsers.size(); i++) { listInfo.add(listUsers.get(i).getId() + " - " + listUsers.get(i).getName()); } }
}
- the above is the class of the Activity to which I send the items to be parsed to the ListView in the form of String but when adding the option it takes me to this screen but without adding any items and I do not know what the problem would be. As I said the database is not empty if you have items, but can not be displayed, thanks in advance if you need any other part of the code let me know I've only put the most important.