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

  • Home
  • SEARCH
  • 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 7759021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:31:17+00:00 2026-06-01T13:31:17+00:00

Hello i am new in android and i really need help with something. I

  • 0

Hello i am new in android and i really need help with something. I got a prepopulate database in my sqlitehelper class and i need a query request returns a String[] table.
Example my database got 3 columns id, name, tel my query will be based on id so the cursor will get {1 mary 2134} i want that to be converted to an String [1 mary 2134]. Dont know if it helps but all my requests will be getting a single row returned, cause the query its primary key based.
my code is something like that:

   public String[] getSingleRow(String id){
    String[] asColumnsToReturn = new String[] { COLUMN_ID,COLUMN_NAME, COLUMN_TELEPHONE}
    Cursor cursor = this.dbSqlite.query(TABLE_NAME, asColumnsToReturn, COLUMN_ID + "=" + id, null, null, null, null);


    //here is where i need help
    String table[]=new String[2];
    int i = 0;

                while (i < table.length) {
                table[i]  = cursor.getString(i);
                i++;
                cursor.moveToNext();
                }
                cursor.close();
return table;
  }

I need that so in my main class i can set textview like:

TextView myTextView = (TextView)findViewById(R.id.textView1);
Table= SQLiteHelper.getSingleRow(id);
myTextView.setText(Table[0]); // "0"for id "1" for name and "2" for telephone 

So my question is how do i convert a single row returned query to a String[]

  • 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-06-01T13:31:18+00:00Added an answer on June 1, 2026 at 1:31 pm

    You seem to be confused on what a cursor is.

    A cursor points to one row in your results response. So if your table looks like this:

    1 | Mary | 1234
    2 | Alice | 134
    3 | Bob | 123
    

    The cursor can only point to one of these rows at a time until you call cursor.movetoNext(). In a single row result, your cursor obviously will never have to use that method.

    Of course, if you want a single ROW and not a TABLE like your variable is named:

    cursor.moveToFirst();
    String row[] = new String[3]
    row[0] = cursor.getString(0);
    row[1] = cursor.getString(1);
    row[2] = cursor.getString(2);
    return row;
    

    Also, I would suggest using constants for the columns as well:

    //declared somewhere as public static final String KEY_NAME = "name";
    cursor.getString(cursor.getColumnIndexByName(KEY_NAME));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i am new in developing Android applications, I need to create an application
Hello Everyone I'm really new bee in android and for that I'm confused to
Hello StackOverflow Users, I am new to android and trying to develop a game
From: http://developer.android.com/resources/tutorials/views/hello-gridview.html , in ImageAdapter class: imageView.setLayoutParams(new GridView.LayoutParams(85, 85)); Look at the new GridView.LayoutParams
class Hello @hello = hello def display puts @hello end end h = Hello.new
Hello I am new to Android programming and I am a bit rusty with
Hello I am new to android programming, I haven't started writing the code for
Hello i m new to android and working on Radio application i gt stuck
I'm new to Android, I've followed the hello world tutorial through and have a
Hello dear programmers, I am very new to android application development and for practice

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.