Adapter not populating RecyclerView
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Hey I have a current application that takes password information from user and stores it into a SQLiteDatabase. My problem is that I cannot get my RecyclerView to populate with this data. I can see that there are entries in the Database.
Code for my Adapter.
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.DataHolder> {
protected ArrayList<PasswordResults> passwords;
class DataHolder extends RecyclerView.ViewHolder {
public TextView id_tv;
public TextView name_tv;
public TextView website_tv;
public TextView desc_tv;
// public Button view_btn; (IGNORE)
public TextView username_tv;
public TextView password_tv;
DataHolder(View v) {
super(v);
id_tv = (TextView) v.findViewById(R.id.tv_id);
name_tv = (TextView) v.findViewById(R.id.tv_name);
website_tv = (TextView) v.findViewById(R.id.tv_website);
desc_tv = (TextView) v.findViewById(R.id.tv_desc);
username_tv = (TextView) v.findViewById(R.id.tv_username);
password_tv = (TextView) v.findViewById(R.id.tv_password);
}
}
DataAdapter(ArrayList<PasswordResults> inData){
passwords = inData;
}
@Override
public DataAdapter.DataHolder onCreateViewHolder(ViewGroup parent, int type){
View v = (View) LayoutInflater.from(parent.getContext()).inflate(R.layout.password_rows, parent, false);
DataHolder passwordHolder = new DataHolder(v);
return passwordHolder;
}
@Override
public void onBindViewHolder(DataHolder holder, int position){
PasswordResults passwordResults = passwords.get(position);
// set values to text views.
holder.id_tv.setText(String.valueOf(position+1));
String name = passwordResults.entryName;
holder.name_tv.setText(name);
String website = passwordResults.website;
holder.website_tv.setText(website);
String desc = passwordResults.description;
holder.desc_tv.setText(desc);
String username = passwordResults.username;
holder.username_tv.setText(username);
String password = passwordResults.password;
holder.password_tv.setText(password);
}
@Override
public int getItemCount(){
return passwords.size();
}
}
Here is my code for my database class
public class Database extends SQLiteOpenHelper {
// version, database name, and table name.
private static final int DATABASE_VERSION = 2;
private static final String DATABASE_NAME = "DB_Passwords";
protected static final String TABLE_NAME = "passwords";
public ArrayList<PasswordResults> passwords;
// creating names for columns.
public final static String COLUMN_ID = "_id";
public final static String COLUMN_NAME = "entryName";
public final static String COLUMN_WEBSITE = "website";
public final static String COLUMN_USERNAME = "username";
public final static String COLUMN_PASSWORD = "password";
public final static String COLUMN_DESC = "description";
// creating table string.
public static final String CREATE_TABLE = "create table if not exists "+TABLE_NAME+" ("
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
+ COLUMN_NAME +" VARCHAR(100), "
+ COLUMN_WEBSITE +" VARCHAR(100), "
+ COLUMN_USERNAME +" VARCHAR(100), "
+ COLUMN_PASSWORD +" VARCHAR(100), "
+ COLUMN_DESC +" TEXT)";
// db helper
public Database(Context c){
super(c, DATABASE_NAME, null, DATABASE_VERSION);
}
// create table when the app is loaded.
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL(CREATE_TABLE);
}
// handle upgrades
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// drop and create new.
db.execSQL("DROP TABLE "+TABLE_NAME);
onCreate(db);
}
public void addPassword(String n, String w, String u, String p, String d) {
// get database.
SQLiteDatabase db = getWritableDatabase();
try {
// add scores.
ContentValues values = new ContentValues();
values.put(COLUMN_NAME, n);
values.put(COLUMN_WEBSITE, w);
values.put(COLUMN_USERNAME, u);
values.put(COLUMN_PASSWORD, p);
values.put(COLUMN_DESC, d);
// insert will handle null values. closing.
db.insert(TABLE_NAME, "", values);
db.close();
} catch (Exception e) {
e.getLocalizedMessage();
}
}
public void removePassword(String id){
// get database.
SQLiteDatabase db = getWritableDatabase();
// delete database then close or print error.
try {
db.delete(TABLE_NAME, "id="+id, null);
db.close();
} catch(Exception e) {
e.getLocalizedMessage();
}
}
public void updatePassword(String id, String n, String w, String u, String p, String d) {
// get database.
SQLiteDatabase db = getWritableDatabase();
//update database then close or print error.
try {
ContentValues values = new ContentValues();
values.put(COLUMN_ID, id);
values.put(COLUMN_NAME, n);
values.put(COLUMN_WEBSITE, w);
values.put(COLUMN_USERNAME, u);
values.put(COLUMN_PASSWORD, p);
values.put(COLUMN_DESC, d);
db.update(TABLE_NAME, values, "_id="+id, null);
db.close();
} catch (Exception e) {
e.getLocalizedMessage();
}
}
public ArrayList<PasswordResults> getPasswords() {
// get database, password array, and select statement.
passwords = new ArrayList<>();
String refQuery = "Select "+COLUMN_NAME+", "+COLUMN_WEBSITE+", "+COLUMN_USERNAME+", "+COLUMN_PASSWORD+", "+COLUMN_DESC+" FROM "+TABLE_NAME;
SQLiteDatabase db = getWritableDatabase();
// link to database
Cursor cursor = db.rawQuery(refQuery, null);
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.entryName = cursor.getString(0);
passwordResults.website = cursor.getString(1);
passwordResults.username = cursor.getString(2);
passwordResults.password = cursor.getString(3);
passwordResults.description = cursor.getString(4);
} while(cursor.moveToNext());
}
db.close();
return passwords;
}
public ArrayList<PasswordResults> getSelectedPassword(String id) {
// get database, password array, and select statement.
passwords = new ArrayList<>();
String refQuery = "Select * from "+TABLE_NAME+" WHERE "+COLUMN_ID+" = "+id;
SQLiteDatabase db = getWritableDatabase();
// link to database
Cursor cursor = db.rawQuery(refQuery, null);
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
} while(cursor.moveToNext());
}
db.close();
return passwords;
}
}
Here is my class that holds the results
public class PasswordResults {
public int id;
public String entryName;
public String website;
public String username;
public String password;
public String description;
}
android android-recyclerview recycler-adapter
add a comment |
Hey I have a current application that takes password information from user and stores it into a SQLiteDatabase. My problem is that I cannot get my RecyclerView to populate with this data. I can see that there are entries in the Database.
Code for my Adapter.
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.DataHolder> {
protected ArrayList<PasswordResults> passwords;
class DataHolder extends RecyclerView.ViewHolder {
public TextView id_tv;
public TextView name_tv;
public TextView website_tv;
public TextView desc_tv;
// public Button view_btn; (IGNORE)
public TextView username_tv;
public TextView password_tv;
DataHolder(View v) {
super(v);
id_tv = (TextView) v.findViewById(R.id.tv_id);
name_tv = (TextView) v.findViewById(R.id.tv_name);
website_tv = (TextView) v.findViewById(R.id.tv_website);
desc_tv = (TextView) v.findViewById(R.id.tv_desc);
username_tv = (TextView) v.findViewById(R.id.tv_username);
password_tv = (TextView) v.findViewById(R.id.tv_password);
}
}
DataAdapter(ArrayList<PasswordResults> inData){
passwords = inData;
}
@Override
public DataAdapter.DataHolder onCreateViewHolder(ViewGroup parent, int type){
View v = (View) LayoutInflater.from(parent.getContext()).inflate(R.layout.password_rows, parent, false);
DataHolder passwordHolder = new DataHolder(v);
return passwordHolder;
}
@Override
public void onBindViewHolder(DataHolder holder, int position){
PasswordResults passwordResults = passwords.get(position);
// set values to text views.
holder.id_tv.setText(String.valueOf(position+1));
String name = passwordResults.entryName;
holder.name_tv.setText(name);
String website = passwordResults.website;
holder.website_tv.setText(website);
String desc = passwordResults.description;
holder.desc_tv.setText(desc);
String username = passwordResults.username;
holder.username_tv.setText(username);
String password = passwordResults.password;
holder.password_tv.setText(password);
}
@Override
public int getItemCount(){
return passwords.size();
}
}
Here is my code for my database class
public class Database extends SQLiteOpenHelper {
// version, database name, and table name.
private static final int DATABASE_VERSION = 2;
private static final String DATABASE_NAME = "DB_Passwords";
protected static final String TABLE_NAME = "passwords";
public ArrayList<PasswordResults> passwords;
// creating names for columns.
public final static String COLUMN_ID = "_id";
public final static String COLUMN_NAME = "entryName";
public final static String COLUMN_WEBSITE = "website";
public final static String COLUMN_USERNAME = "username";
public final static String COLUMN_PASSWORD = "password";
public final static String COLUMN_DESC = "description";
// creating table string.
public static final String CREATE_TABLE = "create table if not exists "+TABLE_NAME+" ("
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
+ COLUMN_NAME +" VARCHAR(100), "
+ COLUMN_WEBSITE +" VARCHAR(100), "
+ COLUMN_USERNAME +" VARCHAR(100), "
+ COLUMN_PASSWORD +" VARCHAR(100), "
+ COLUMN_DESC +" TEXT)";
// db helper
public Database(Context c){
super(c, DATABASE_NAME, null, DATABASE_VERSION);
}
// create table when the app is loaded.
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL(CREATE_TABLE);
}
// handle upgrades
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// drop and create new.
db.execSQL("DROP TABLE "+TABLE_NAME);
onCreate(db);
}
public void addPassword(String n, String w, String u, String p, String d) {
// get database.
SQLiteDatabase db = getWritableDatabase();
try {
// add scores.
ContentValues values = new ContentValues();
values.put(COLUMN_NAME, n);
values.put(COLUMN_WEBSITE, w);
values.put(COLUMN_USERNAME, u);
values.put(COLUMN_PASSWORD, p);
values.put(COLUMN_DESC, d);
// insert will handle null values. closing.
db.insert(TABLE_NAME, "", values);
db.close();
} catch (Exception e) {
e.getLocalizedMessage();
}
}
public void removePassword(String id){
// get database.
SQLiteDatabase db = getWritableDatabase();
// delete database then close or print error.
try {
db.delete(TABLE_NAME, "id="+id, null);
db.close();
} catch(Exception e) {
e.getLocalizedMessage();
}
}
public void updatePassword(String id, String n, String w, String u, String p, String d) {
// get database.
SQLiteDatabase db = getWritableDatabase();
//update database then close or print error.
try {
ContentValues values = new ContentValues();
values.put(COLUMN_ID, id);
values.put(COLUMN_NAME, n);
values.put(COLUMN_WEBSITE, w);
values.put(COLUMN_USERNAME, u);
values.put(COLUMN_PASSWORD, p);
values.put(COLUMN_DESC, d);
db.update(TABLE_NAME, values, "_id="+id, null);
db.close();
} catch (Exception e) {
e.getLocalizedMessage();
}
}
public ArrayList<PasswordResults> getPasswords() {
// get database, password array, and select statement.
passwords = new ArrayList<>();
String refQuery = "Select "+COLUMN_NAME+", "+COLUMN_WEBSITE+", "+COLUMN_USERNAME+", "+COLUMN_PASSWORD+", "+COLUMN_DESC+" FROM "+TABLE_NAME;
SQLiteDatabase db = getWritableDatabase();
// link to database
Cursor cursor = db.rawQuery(refQuery, null);
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.entryName = cursor.getString(0);
passwordResults.website = cursor.getString(1);
passwordResults.username = cursor.getString(2);
passwordResults.password = cursor.getString(3);
passwordResults.description = cursor.getString(4);
} while(cursor.moveToNext());
}
db.close();
return passwords;
}
public ArrayList<PasswordResults> getSelectedPassword(String id) {
// get database, password array, and select statement.
passwords = new ArrayList<>();
String refQuery = "Select * from "+TABLE_NAME+" WHERE "+COLUMN_ID+" = "+id;
SQLiteDatabase db = getWritableDatabase();
// link to database
Cursor cursor = db.rawQuery(refQuery, null);
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
} while(cursor.moveToNext());
}
db.close();
return passwords;
}
}
Here is my class that holds the results
public class PasswordResults {
public int id;
public String entryName;
public String website;
public String username;
public String password;
public String description;
}
android android-recyclerview recycler-adapter
please show how you pass data to DataAdapter.java
– Jins Lukose
Nov 22 '18 at 6:53
add a comment |
Hey I have a current application that takes password information from user and stores it into a SQLiteDatabase. My problem is that I cannot get my RecyclerView to populate with this data. I can see that there are entries in the Database.
Code for my Adapter.
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.DataHolder> {
protected ArrayList<PasswordResults> passwords;
class DataHolder extends RecyclerView.ViewHolder {
public TextView id_tv;
public TextView name_tv;
public TextView website_tv;
public TextView desc_tv;
// public Button view_btn; (IGNORE)
public TextView username_tv;
public TextView password_tv;
DataHolder(View v) {
super(v);
id_tv = (TextView) v.findViewById(R.id.tv_id);
name_tv = (TextView) v.findViewById(R.id.tv_name);
website_tv = (TextView) v.findViewById(R.id.tv_website);
desc_tv = (TextView) v.findViewById(R.id.tv_desc);
username_tv = (TextView) v.findViewById(R.id.tv_username);
password_tv = (TextView) v.findViewById(R.id.tv_password);
}
}
DataAdapter(ArrayList<PasswordResults> inData){
passwords = inData;
}
@Override
public DataAdapter.DataHolder onCreateViewHolder(ViewGroup parent, int type){
View v = (View) LayoutInflater.from(parent.getContext()).inflate(R.layout.password_rows, parent, false);
DataHolder passwordHolder = new DataHolder(v);
return passwordHolder;
}
@Override
public void onBindViewHolder(DataHolder holder, int position){
PasswordResults passwordResults = passwords.get(position);
// set values to text views.
holder.id_tv.setText(String.valueOf(position+1));
String name = passwordResults.entryName;
holder.name_tv.setText(name);
String website = passwordResults.website;
holder.website_tv.setText(website);
String desc = passwordResults.description;
holder.desc_tv.setText(desc);
String username = passwordResults.username;
holder.username_tv.setText(username);
String password = passwordResults.password;
holder.password_tv.setText(password);
}
@Override
public int getItemCount(){
return passwords.size();
}
}
Here is my code for my database class
public class Database extends SQLiteOpenHelper {
// version, database name, and table name.
private static final int DATABASE_VERSION = 2;
private static final String DATABASE_NAME = "DB_Passwords";
protected static final String TABLE_NAME = "passwords";
public ArrayList<PasswordResults> passwords;
// creating names for columns.
public final static String COLUMN_ID = "_id";
public final static String COLUMN_NAME = "entryName";
public final static String COLUMN_WEBSITE = "website";
public final static String COLUMN_USERNAME = "username";
public final static String COLUMN_PASSWORD = "password";
public final static String COLUMN_DESC = "description";
// creating table string.
public static final String CREATE_TABLE = "create table if not exists "+TABLE_NAME+" ("
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
+ COLUMN_NAME +" VARCHAR(100), "
+ COLUMN_WEBSITE +" VARCHAR(100), "
+ COLUMN_USERNAME +" VARCHAR(100), "
+ COLUMN_PASSWORD +" VARCHAR(100), "
+ COLUMN_DESC +" TEXT)";
// db helper
public Database(Context c){
super(c, DATABASE_NAME, null, DATABASE_VERSION);
}
// create table when the app is loaded.
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL(CREATE_TABLE);
}
// handle upgrades
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// drop and create new.
db.execSQL("DROP TABLE "+TABLE_NAME);
onCreate(db);
}
public void addPassword(String n, String w, String u, String p, String d) {
// get database.
SQLiteDatabase db = getWritableDatabase();
try {
// add scores.
ContentValues values = new ContentValues();
values.put(COLUMN_NAME, n);
values.put(COLUMN_WEBSITE, w);
values.put(COLUMN_USERNAME, u);
values.put(COLUMN_PASSWORD, p);
values.put(COLUMN_DESC, d);
// insert will handle null values. closing.
db.insert(TABLE_NAME, "", values);
db.close();
} catch (Exception e) {
e.getLocalizedMessage();
}
}
public void removePassword(String id){
// get database.
SQLiteDatabase db = getWritableDatabase();
// delete database then close or print error.
try {
db.delete(TABLE_NAME, "id="+id, null);
db.close();
} catch(Exception e) {
e.getLocalizedMessage();
}
}
public void updatePassword(String id, String n, String w, String u, String p, String d) {
// get database.
SQLiteDatabase db = getWritableDatabase();
//update database then close or print error.
try {
ContentValues values = new ContentValues();
values.put(COLUMN_ID, id);
values.put(COLUMN_NAME, n);
values.put(COLUMN_WEBSITE, w);
values.put(COLUMN_USERNAME, u);
values.put(COLUMN_PASSWORD, p);
values.put(COLUMN_DESC, d);
db.update(TABLE_NAME, values, "_id="+id, null);
db.close();
} catch (Exception e) {
e.getLocalizedMessage();
}
}
public ArrayList<PasswordResults> getPasswords() {
// get database, password array, and select statement.
passwords = new ArrayList<>();
String refQuery = "Select "+COLUMN_NAME+", "+COLUMN_WEBSITE+", "+COLUMN_USERNAME+", "+COLUMN_PASSWORD+", "+COLUMN_DESC+" FROM "+TABLE_NAME;
SQLiteDatabase db = getWritableDatabase();
// link to database
Cursor cursor = db.rawQuery(refQuery, null);
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.entryName = cursor.getString(0);
passwordResults.website = cursor.getString(1);
passwordResults.username = cursor.getString(2);
passwordResults.password = cursor.getString(3);
passwordResults.description = cursor.getString(4);
} while(cursor.moveToNext());
}
db.close();
return passwords;
}
public ArrayList<PasswordResults> getSelectedPassword(String id) {
// get database, password array, and select statement.
passwords = new ArrayList<>();
String refQuery = "Select * from "+TABLE_NAME+" WHERE "+COLUMN_ID+" = "+id;
SQLiteDatabase db = getWritableDatabase();
// link to database
Cursor cursor = db.rawQuery(refQuery, null);
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
} while(cursor.moveToNext());
}
db.close();
return passwords;
}
}
Here is my class that holds the results
public class PasswordResults {
public int id;
public String entryName;
public String website;
public String username;
public String password;
public String description;
}
android android-recyclerview recycler-adapter
Hey I have a current application that takes password information from user and stores it into a SQLiteDatabase. My problem is that I cannot get my RecyclerView to populate with this data. I can see that there are entries in the Database.
Code for my Adapter.
public class DataAdapter extends RecyclerView.Adapter<DataAdapter.DataHolder> {
protected ArrayList<PasswordResults> passwords;
class DataHolder extends RecyclerView.ViewHolder {
public TextView id_tv;
public TextView name_tv;
public TextView website_tv;
public TextView desc_tv;
// public Button view_btn; (IGNORE)
public TextView username_tv;
public TextView password_tv;
DataHolder(View v) {
super(v);
id_tv = (TextView) v.findViewById(R.id.tv_id);
name_tv = (TextView) v.findViewById(R.id.tv_name);
website_tv = (TextView) v.findViewById(R.id.tv_website);
desc_tv = (TextView) v.findViewById(R.id.tv_desc);
username_tv = (TextView) v.findViewById(R.id.tv_username);
password_tv = (TextView) v.findViewById(R.id.tv_password);
}
}
DataAdapter(ArrayList<PasswordResults> inData){
passwords = inData;
}
@Override
public DataAdapter.DataHolder onCreateViewHolder(ViewGroup parent, int type){
View v = (View) LayoutInflater.from(parent.getContext()).inflate(R.layout.password_rows, parent, false);
DataHolder passwordHolder = new DataHolder(v);
return passwordHolder;
}
@Override
public void onBindViewHolder(DataHolder holder, int position){
PasswordResults passwordResults = passwords.get(position);
// set values to text views.
holder.id_tv.setText(String.valueOf(position+1));
String name = passwordResults.entryName;
holder.name_tv.setText(name);
String website = passwordResults.website;
holder.website_tv.setText(website);
String desc = passwordResults.description;
holder.desc_tv.setText(desc);
String username = passwordResults.username;
holder.username_tv.setText(username);
String password = passwordResults.password;
holder.password_tv.setText(password);
}
@Override
public int getItemCount(){
return passwords.size();
}
}
Here is my code for my database class
public class Database extends SQLiteOpenHelper {
// version, database name, and table name.
private static final int DATABASE_VERSION = 2;
private static final String DATABASE_NAME = "DB_Passwords";
protected static final String TABLE_NAME = "passwords";
public ArrayList<PasswordResults> passwords;
// creating names for columns.
public final static String COLUMN_ID = "_id";
public final static String COLUMN_NAME = "entryName";
public final static String COLUMN_WEBSITE = "website";
public final static String COLUMN_USERNAME = "username";
public final static String COLUMN_PASSWORD = "password";
public final static String COLUMN_DESC = "description";
// creating table string.
public static final String CREATE_TABLE = "create table if not exists "+TABLE_NAME+" ("
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "
+ COLUMN_NAME +" VARCHAR(100), "
+ COLUMN_WEBSITE +" VARCHAR(100), "
+ COLUMN_USERNAME +" VARCHAR(100), "
+ COLUMN_PASSWORD +" VARCHAR(100), "
+ COLUMN_DESC +" TEXT)";
// db helper
public Database(Context c){
super(c, DATABASE_NAME, null, DATABASE_VERSION);
}
// create table when the app is loaded.
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL(CREATE_TABLE);
}
// handle upgrades
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// drop and create new.
db.execSQL("DROP TABLE "+TABLE_NAME);
onCreate(db);
}
public void addPassword(String n, String w, String u, String p, String d) {
// get database.
SQLiteDatabase db = getWritableDatabase();
try {
// add scores.
ContentValues values = new ContentValues();
values.put(COLUMN_NAME, n);
values.put(COLUMN_WEBSITE, w);
values.put(COLUMN_USERNAME, u);
values.put(COLUMN_PASSWORD, p);
values.put(COLUMN_DESC, d);
// insert will handle null values. closing.
db.insert(TABLE_NAME, "", values);
db.close();
} catch (Exception e) {
e.getLocalizedMessage();
}
}
public void removePassword(String id){
// get database.
SQLiteDatabase db = getWritableDatabase();
// delete database then close or print error.
try {
db.delete(TABLE_NAME, "id="+id, null);
db.close();
} catch(Exception e) {
e.getLocalizedMessage();
}
}
public void updatePassword(String id, String n, String w, String u, String p, String d) {
// get database.
SQLiteDatabase db = getWritableDatabase();
//update database then close or print error.
try {
ContentValues values = new ContentValues();
values.put(COLUMN_ID, id);
values.put(COLUMN_NAME, n);
values.put(COLUMN_WEBSITE, w);
values.put(COLUMN_USERNAME, u);
values.put(COLUMN_PASSWORD, p);
values.put(COLUMN_DESC, d);
db.update(TABLE_NAME, values, "_id="+id, null);
db.close();
} catch (Exception e) {
e.getLocalizedMessage();
}
}
public ArrayList<PasswordResults> getPasswords() {
// get database, password array, and select statement.
passwords = new ArrayList<>();
String refQuery = "Select "+COLUMN_NAME+", "+COLUMN_WEBSITE+", "+COLUMN_USERNAME+", "+COLUMN_PASSWORD+", "+COLUMN_DESC+" FROM "+TABLE_NAME;
SQLiteDatabase db = getWritableDatabase();
// link to database
Cursor cursor = db.rawQuery(refQuery, null);
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.entryName = cursor.getString(0);
passwordResults.website = cursor.getString(1);
passwordResults.username = cursor.getString(2);
passwordResults.password = cursor.getString(3);
passwordResults.description = cursor.getString(4);
} while(cursor.moveToNext());
}
db.close();
return passwords;
}
public ArrayList<PasswordResults> getSelectedPassword(String id) {
// get database, password array, and select statement.
passwords = new ArrayList<>();
String refQuery = "Select * from "+TABLE_NAME+" WHERE "+COLUMN_ID+" = "+id;
SQLiteDatabase db = getWritableDatabase();
// link to database
Cursor cursor = db.rawQuery(refQuery, null);
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
} while(cursor.moveToNext());
}
db.close();
return passwords;
}
}
Here is my class that holds the results
public class PasswordResults {
public int id;
public String entryName;
public String website;
public String username;
public String password;
public String description;
}
android android-recyclerview recycler-adapter
android android-recyclerview recycler-adapter
edited Nov 26 '18 at 15:37
Bugs
4,15992637
4,15992637
asked Nov 21 '18 at 21:04
JOhnJOhn
306
306
please show how you pass data to DataAdapter.java
– Jins Lukose
Nov 22 '18 at 6:53
add a comment |
please show how you pass data to DataAdapter.java
– Jins Lukose
Nov 22 '18 at 6:53
please show how you pass data to DataAdapter.java
– Jins Lukose
Nov 22 '18 at 6:53
please show how you pass data to DataAdapter.java
– Jins Lukose
Nov 22 '18 at 6:53
add a comment |
2 Answers
2
active
oldest
votes
In both methods getPasswords() and getSelectedPasswords() you are creating an empty ArrayList on these lines:
passwords = new ArrayList<>();
but you then return passwords without ever adding the passwordResults into it. In getSelectedPasswords(), the code below:
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
} while(cursor.moveToNext());
}
db.close();
return passwords;
should be changed to:
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
passwords.add(passwordResults); //This line is missing!
} while(cursor.moveToNext());
}
db.close();
return passwords;
the same must also be added to the getPasswords() method.
my hero thank you so much lmao.
– JOhn
Nov 26 '18 at 0:38
No worries, if you could upvote the answer as well that would be appreciated
– N1234
Nov 30 '18 at 15:49
add a comment |
I dont have enough reputation to comment but this might help.
Once you populate your ArrayList,did you call ?
adapter.notifyDataSetChanged();
If not, you must do it. If yes, make sure your recycler view is surely not being populated with the data and theres not an issue with your layout xml file. Because often if your layout file for the recyclerView is not designed correctly,you wont be able to visibly see it even if the recyclerView and it's adapter is doing it's work perfectly fine from the java code.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420460%2fadapter-not-populating-recyclerview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In both methods getPasswords() and getSelectedPasswords() you are creating an empty ArrayList on these lines:
passwords = new ArrayList<>();
but you then return passwords without ever adding the passwordResults into it. In getSelectedPasswords(), the code below:
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
} while(cursor.moveToNext());
}
db.close();
return passwords;
should be changed to:
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
passwords.add(passwordResults); //This line is missing!
} while(cursor.moveToNext());
}
db.close();
return passwords;
the same must also be added to the getPasswords() method.
my hero thank you so much lmao.
– JOhn
Nov 26 '18 at 0:38
No worries, if you could upvote the answer as well that would be appreciated
– N1234
Nov 30 '18 at 15:49
add a comment |
In both methods getPasswords() and getSelectedPasswords() you are creating an empty ArrayList on these lines:
passwords = new ArrayList<>();
but you then return passwords without ever adding the passwordResults into it. In getSelectedPasswords(), the code below:
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
} while(cursor.moveToNext());
}
db.close();
return passwords;
should be changed to:
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
passwords.add(passwordResults); //This line is missing!
} while(cursor.moveToNext());
}
db.close();
return passwords;
the same must also be added to the getPasswords() method.
my hero thank you so much lmao.
– JOhn
Nov 26 '18 at 0:38
No worries, if you could upvote the answer as well that would be appreciated
– N1234
Nov 30 '18 at 15:49
add a comment |
In both methods getPasswords() and getSelectedPasswords() you are creating an empty ArrayList on these lines:
passwords = new ArrayList<>();
but you then return passwords without ever adding the passwordResults into it. In getSelectedPasswords(), the code below:
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
} while(cursor.moveToNext());
}
db.close();
return passwords;
should be changed to:
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
passwords.add(passwordResults); //This line is missing!
} while(cursor.moveToNext());
}
db.close();
return passwords;
the same must also be added to the getPasswords() method.
In both methods getPasswords() and getSelectedPasswords() you are creating an empty ArrayList on these lines:
passwords = new ArrayList<>();
but you then return passwords without ever adding the passwordResults into it. In getSelectedPasswords(), the code below:
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
} while(cursor.moveToNext());
}
db.close();
return passwords;
should be changed to:
if(cursor.moveToFirst()) {
do {
PasswordResults passwordResults = new PasswordResults();
passwordResults.id = cursor.getInt(0);
passwordResults.entryName = cursor.getString(1);
passwordResults.website = cursor.getString(2);
passwordResults.username = cursor.getString(3);
passwordResults.password = cursor.getString(4);
passwordResults.description = cursor.getString(5);
passwords.add(passwordResults); //This line is missing!
} while(cursor.moveToNext());
}
db.close();
return passwords;
the same must also be added to the getPasswords() method.
answered Nov 21 '18 at 23:12
N1234N1234
156110
156110
my hero thank you so much lmao.
– JOhn
Nov 26 '18 at 0:38
No worries, if you could upvote the answer as well that would be appreciated
– N1234
Nov 30 '18 at 15:49
add a comment |
my hero thank you so much lmao.
– JOhn
Nov 26 '18 at 0:38
No worries, if you could upvote the answer as well that would be appreciated
– N1234
Nov 30 '18 at 15:49
my hero thank you so much lmao.
– JOhn
Nov 26 '18 at 0:38
my hero thank you so much lmao.
– JOhn
Nov 26 '18 at 0:38
No worries, if you could upvote the answer as well that would be appreciated
– N1234
Nov 30 '18 at 15:49
No worries, if you could upvote the answer as well that would be appreciated
– N1234
Nov 30 '18 at 15:49
add a comment |
I dont have enough reputation to comment but this might help.
Once you populate your ArrayList,did you call ?
adapter.notifyDataSetChanged();
If not, you must do it. If yes, make sure your recycler view is surely not being populated with the data and theres not an issue with your layout xml file. Because often if your layout file for the recyclerView is not designed correctly,you wont be able to visibly see it even if the recyclerView and it's adapter is doing it's work perfectly fine from the java code.
add a comment |
I dont have enough reputation to comment but this might help.
Once you populate your ArrayList,did you call ?
adapter.notifyDataSetChanged();
If not, you must do it. If yes, make sure your recycler view is surely not being populated with the data and theres not an issue with your layout xml file. Because often if your layout file for the recyclerView is not designed correctly,you wont be able to visibly see it even if the recyclerView and it's adapter is doing it's work perfectly fine from the java code.
add a comment |
I dont have enough reputation to comment but this might help.
Once you populate your ArrayList,did you call ?
adapter.notifyDataSetChanged();
If not, you must do it. If yes, make sure your recycler view is surely not being populated with the data and theres not an issue with your layout xml file. Because often if your layout file for the recyclerView is not designed correctly,you wont be able to visibly see it even if the recyclerView and it's adapter is doing it's work perfectly fine from the java code.
I dont have enough reputation to comment but this might help.
Once you populate your ArrayList,did you call ?
adapter.notifyDataSetChanged();
If not, you must do it. If yes, make sure your recycler view is surely not being populated with the data and theres not an issue with your layout xml file. Because often if your layout file for the recyclerView is not designed correctly,you wont be able to visibly see it even if the recyclerView and it's adapter is doing it's work perfectly fine from the java code.
answered Nov 21 '18 at 21:44
schrodingers_cat16schrodingers_cat16
264
264
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53420460%2fadapter-not-populating-recyclerview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
please show how you pass data to DataAdapter.java
– Jins Lukose
Nov 22 '18 at 6:53