Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7586215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:22:19+00:00 2026-05-30T19:22:19+00:00

I want to show contact info using SimpleCursorAdaptor , when i get info from

  • 0

I want to show contact info using SimpleCursorAdaptor , when i get info from database it does not show anything . but i have checked through cursor.count() there is data exist .

this is listactivity

public class Contacts extends ListActivity {

private ArrayList<TempInfo> contactsList = null;
// Attributes

private static String name = "";
private static String phone = "";
private static int rowId = 0;

@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.contact_list);

    contactsList = new ArrayList<TempInfo>();
    CardsDatabase info = new CardsDatabase(this);
    info.open();

    Cursor c = info.geTContactsData();
    Log.d("cursor length",Integer.toString(c.getCount()));
    c.moveToFirst();
    while (c.isAfterLast() == false) {
        name = c.getString(c.getColumnIndex(CardsDatabase.NAME_R));
        phone = c.getString(c.getColumnIndex(CardsDatabase.PHONE_R));
        rowId = c.getInt(c.getColumnIndex(CardsDatabase.ROW_R));

        TempInfo s = new TempInfo(rowId, name, phone);
        contactsList.add(s);

        c.moveToNext();
    }

    c.close();

    Cursor cursor = info.geTContactsData();
    startManagingCursor(cursor);

    String[] columns = new String[] { CardsDatabase.ROW_R,
            CardsDatabase.NAME_R, CardsDatabase.PHONE_R };

    int[] to = new int[] { R.id.row_id, R.id.contact_name,
            R.id.contact_number };

    SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(Contacts.this,
            R.layout.contact_list_entry, cursor, columns, to);
    this.setListAdapter(mAdapter);
    cursor.close();

}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

    super.onListItemClick(l, v, position, id);
    TempInfo tempInfo = contactsList.get(position);

    Intent i = new Intent(Contacts.this, ContactsDetail.class);
    Bundle bundle = new Bundle();
    bundle.putInt("rowid", tempInfo.rowid);
    i.putExtra("personBundle", bundle);
    startActivity(i);

}

}

Here is contact_list xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#66000000"
    android:cacheColorHint="#6E000000"
    android:paddingLeft="5dp"
    android:text="   Contacts"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textColor="#ffffff" />

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:cacheColorHint="#00000000" >
</ListView>

This is contact_list_entry xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >

<TextView
    android:id="@+id/row_id"
    android:layout_width="25dp"
    android:layout_height="fill_parent"
    android:background="#5C5858"
    android:textColor="#ffffff" />

<LinearLayout
    android:layout_width="0dip"
    android:layout_height="fill_parent"
    android:layout_weight="1"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/contact_name"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/contact_number"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:ellipsize="marquee"
        android:singleLine="true" />
</LinearLayout>

</LinearLayout>

This is database

public class CardsDatabase {

public static String USERTEMPLATE = "user";
public static String MYCARD = "mycard";
public static String ALERT = "alert";

public static String USER = "user";
public static String NAME = "name";
public static String COMPANY = "company";
public static String TITLE = "title";
public static String ADDRESS = "address";
public static String PHONE = "phone";
public static String CEL = "cel";
public static String EMAIL = "email";
public static String PHOTO = "photo";

public static String ROW_R = "_id";
public static String NAME_R = "rname";
public static String COMPANY_R = "rcompany";
public static String TITLE_R = "rtitle";
public static String ADDRESS_R = "raddress";
public static String PHONE_R = "rphone";
public static String CEL_R = "rcel";
public static String EMAIL_R = "remail";
public static String PHOTO_R = "rphoto";
public static String TEMPLATE_R = "rtemplate";

public static String MAC = "macaddress";

private static String DATABASE_NAME = "CardsDatabase";
public static String DATABASE_TABLE_TEMPLATE = "TemplateTable";
public static String DATABASE_TABLE_MYTABLE = "MYTable";
public static String DATABASE_TABLE_CONTACTS = "ContactsTable";
public static String DATABASE_TABLE_CONTACTS_REMOTE = "rContactsTable";

private static int DATABASE_VERSION = 1;

private DbHelper ourHelper;
private final Context ourContext;
private SQLiteDatabase ourDatabase;

private static class DbHelper extends SQLiteOpenHelper {

    public DbHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        // Log.d(Tag,"Inner on create called");
        db.execSQL("CREATE TABLE " + DATABASE_TABLE_TEMPLATE + " ("
                + USERTEMPLATE + " TEXT NOT NULL," + MYCARD
                + " TEXT NOT NULL," + ALERT + " TEXT NOT NULL" + ");");

        db.execSQL("CREATE TABLE " + DATABASE_TABLE_MYTABLE + " (" + USER
                + " TEXT NOT NULL," + NAME + " TEXT NOT NULL," + COMPANY
                + " TEXT," + TITLE + " TEXT," + ADDRESS + " TEXT," + PHONE
                + " TEXT NOT NULL," + CEL + " TEXT," + EMAIL
                + " TEXT NOT NULL," + PHOTO + " BLOB" + ");");

        db.execSQL("CREATE TABLE " + DATABASE_TABLE_CONTACTS_REMOTE + " ("
                + ROW_R + " integer primary key autoincrement," + NAME_R
                + " TEXT NOT NULL," + COMPANY_R + " TEXT," + TITLE_R
                + " TEXT," + ADDRESS_R + " TEXT," + TEMPLATE_R
                + " TEXT NOT NULL," + PHONE_R + " TEXT NOT NULL," + CEL_R
                + " TEXT," + EMAIL_R + " TEXT NOT NULL," + PHOTO_R
                + " BLOB" + ");");

        db.execSQL("CREATE TABLE " + DATABASE_TABLE_CONTACTS + " (" + MAC
                + " TEXT NOT NULL" + ");");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS" + DATABASE_TABLE_TEMPLATE);
        db.execSQL("DROP TABLE IF EXISTS" + DATABASE_TABLE_MYTABLE);
        db.execSQL("DROP TABLE IF EXISTS" + DATABASE_TABLE_CONTACTS);
        db.execSQL("DROP TABLE IF EXISTS" + DATABASE_TABLE_CONTACTS_REMOTE);

        onCreate(db);
    }

}

public CardsDatabase(Context c) {
    ourContext = c;
}

public CardsDatabase open() throws SQLException {
    ourHelper = new DbHelper(ourContext);
    ourDatabase = ourHelper.getWritableDatabase();
    return this;
}

public void close() {
    ourHelper.close();
}

public void createEntry(int type, ContentValues cv) {
    // TODO Auto-generated method stub

    switch (type) {
    case 1:
        ourDatabase.insert(DATABASE_TABLE_TEMPLATE, null, cv);
        break;
    case 2:
        ourDatabase.insert(DATABASE_TABLE_MYTABLE, null, cv);
        break;
    case 3:
        ourDatabase.insert(DATABASE_TABLE_CONTACTS, null, cv);
        break;
    case 4:
        ourDatabase.insert(DATABASE_TABLE_CONTACTS_REMOTE, null, cv);
        break;
    }

}

public Cursor getTemplate() throws SQLException {
    // TODO Auto-generated method stub

    String[] columns = new String[] { USERTEMPLATE, MYCARD, ALERT };

    Cursor c = ourDatabase.query(DATABASE_TABLE_TEMPLATE, columns, null,
            null, null, null, null);

    return c;
}

public Cursor getMyData() throws SQLException {
    // TODO Auto-generated method stub

    String[] columns = new String[] { USER, NAME, COMPANY, TITLE, ADDRESS,
            PHONE, CEL, EMAIL, PHOTO };

    Cursor c = ourDatabase.query(DATABASE_TABLE_MYTABLE, columns, null,
            null, null, null, null);

    return c;
}

public Cursor geTContactsData() throws SQLException {
    // TODO Auto-generated method stub

    String[] columns = new String[] { ROW_R, NAME_R, PHONE_R};

    Cursor c = ourDatabase.query(DATABASE_TABLE_CONTACTS_REMOTE, columns,
            null, null, null, null, null);

    return c;
}

public Cursor getDetailData(int row_id) {

    String WHERE = String.format("%s='%d'", ROW_R, row_id);
    String[] columns = new String[] { NAME_R, TITLE_R, ADDRESS_R, PHONE_R,
            CEL_R, EMAIL_R, TEMPLATE_R, PHOTO_R };

    Cursor c = ourDatabase.query(DATABASE_TABLE_CONTACTS_REMOTE, columns,
            WHERE, null, null, null, null);

    return c;
}

public boolean contactExist(String mac_adr) throws SQLException {
    // TODO Auto-generated method stub

    String[] columns = new String[] { MAC };

    String WHERE = String.format("%s='%s'", MAC, mac_adr);
    Cursor c = ourDatabase.query(DATABASE_TABLE_CONTACTS, columns, WHERE,
            null, null, null, null);

    return c.getCount() > 0 ? true : false;
}

public void updateTemplate(ContentValues cv) {
    String m = "me";
    String WHERE = String.format("%s='%s'", USERTEMPLATE, m);
    ourDatabase.update(DATABASE_TABLE_TEMPLATE, cv, WHERE, null);
}

public void updateMytable(ContentValues cv) {
    String m = "me";
    String WHERE = String.format("%s='%s'", USERTEMPLATE, m);
    ourDatabase.update(DATABASE_TABLE_MYTABLE, cv, WHERE, null);
}
}

Logcat showing this

02-28 09:18:09.702: D/cursor length(5152): 10
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:22:20+00:00Added an answer on May 30, 2026 at 7:22 pm

    Remove cursor.close(); from your code,after you set the adapter in onCreate().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have created one listview.now i want to show data(contact no.,name) from contactlist of
I have a contact form with two radio buttons. But I need to show
The problem I want to solve: Get all the contacts info like name and
I have an app that can show a stream of tweets from a twitter
I want to show data in this format, 12-22-2011 11:00:00 [12-22-2011 11:13:39] Warning: Contact
i am developing one contact application . I want to show contact image to
I have my site built with jquery show/hide divs and want to have a
I want to generate a list from a table in my database. That list
I have a contact form open in thickbox i want when user click on
I want to show a link named contact-us in my website which when click

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.