-2

I am writing simple phone contact. I add people's names,phones,e-mails. Only names must be shown in listView. I can see list's row, but can not see names on rows. They are invisible.

This method is showing infos of people:

public List<Kontak> kisiOku(){
    SQLiteDatabase db = this.getReadableDatabase();
    List<Kontak> list = new ArrayList<>();
    String[] kolon = {"id","isim","tel","mail"};
    Cursor c = db.query("kisi",kolon,null,null,null,null,null);
    c.moveToFirst();
    while (!c.isAfterLast()){
        String isim = c.getString(c.getColumnIndex("isim"));
        Kontak knt = new Kontak();
        knt.setIsim(isim);
        list.add(knt);
        c.moveToNext();
    }
    c.close();
    db.close();
    return list;
}

This is my data class:

public class Kontak {

int id;
String isim;
String tel;
String mail;

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getIsim() {
    return isim;
}

public void setIsim(String isim) {
    this.isim = isim;
}

public String getTel() {
    return tel;
}

public void setTel(String tel) {
    this.tel = tel;
}

public String getMail() {
    return mail;
}

public void setMail(String mail) {
    this.mail = mail;
}

public String toString(){return isim;}}

This is adapter part:

    k = new Kontak();
    dbHelper = new DbHelper(this);
    list = dbHelper.kisiOku();
    adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, list);
    listView.setAdapter(adapter);

1 Answers1

-1

In your code snippet you are querying from the SQLite and updating isim (which I assume to be name field) in the Kontak object. The same object is being appended to the list. The other fields like mail and phone are not being updated in the Kontak object.

Also, the toString method of Kontak class returns only isim. Consider adding mail and phone number details to the output string.

krisnik
  • 1,406
  • 11
  • 18
  • 1
    No. OP is creating a new contact, setting the name, and adding that contact to the list. OP also states he only wants to use the name for the ListView. The function returns that list of contacts with only the name set, which is what OP wants. I suspect the problem is when they come to populate that data via the ListView or RecyclerView's adapter. – Michael Dodd Feb 05 '18 at 17:40
  • Yeah! My bad! I read the question as only names are shown, instead of only names must be shown! In that case, to debug the issue, check if cursor returns any data and also, check the contents of the list before return statement. If the method returns data, as you said, the issue is with View / Adapter. – krisnik Feb 05 '18 at 17:55
  • I solved this problem. Thank you everyone :) – Şafak Sever Feb 05 '18 at 19:54