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.
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
TextViewin 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.