0

I am trying to write a simple app just to display on screen the results on a sql query.

public class ContactLookup extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.main);
         Cursor c = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, 
                null, null, null, null
                );
    }
}

How exactly do I print the results of the cursor? Everything I find goes into to way more detail then I need at the moment... I just want to know how to get that variable printed on screen.

1 Answer 1

1

You'll need to have something that shows text (or whatever you get from your DB). Most likely this will be a simple TextView (you can do this in the XML-Layout or in Java-Code).

If you declared your TextView in the XML-Layout, then you'll need to find the TextView in order to set it's text.

After that, you'll want to move the Cursor to the first set of data in it so you can read your results from it.

After that, you can simply use the Cursor's getXX()-methods to get your values form the result-set.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Lukas, you have pointed me in the correct direction... I was able to get all the contact names printed on the screen. I appreciate the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.