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 8609609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:55:16+00:00 2026-06-12T03:55:16+00:00

I have a TextView and a String randomWord. When the app starts I open

  • 0

I have a TextView and a String randomWord. When the app starts I open my db and call a method db.open() which opens it and then the db.randomize() which calls the randomize() method and queries the db for random entry and returns it as a String. Thereafter I just want to MyTextView.setText (randomWord); but when app is running nothing is displaying. I have tried to hardcode in setText (“whatever”) and that is shown.

So I guess I have done wrong in the randomize or something because I don’t get a word from the db.

This is what I try to do:

 db.open();
        db.randomize(generatedWord);
        //text = new SpannableString(generatedWord);
        //text.setSpan(new ForegroundColorSpan(Color.WHITE), 0, text.length(), 0);  
        wordHolder.setText("" + generatedWord);
        db.close();

This is my random method:

  public Cursor randomize(String word) {
            @SuppressWarnings("unused")
            Cursor cursor;
            return cursor =  this.db.query("tblnames ORDER BY RANDOM() LIMIT 1", new String[] { "*" }, null, null, null, null, null);
        }

My DB has two columns: “_id” and “word”

"create table tblnames (_id integer primary key autoincrement, "
     + "words text not null);"

Can it have to do that I don’t specify the _id and word somewhere in the randomize()?

ALSO: I tried setText (generatedWord) as well as setText (” +generatedWord);
ALSO: no errors while running.

  • 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-12T03:55:17+00:00Added an answer on June 12, 2026 at 3:55 am

    You aren’t returning a String with your randomize() method.

    This should give you the desired affect

    db.open();
    //text = new SpannableString(generatedWord);
    //text.setSpan(new ForegroundColorSpan(Color.WHITE), 0, text.length(), 0);  
    wordHolder.setText(db.randomize());
    db.close();
    

    And in your DB you need to return the string value of the column you want from your cursor, not the cursor itself. http://developer.android.com/reference/android/database/Cursor.html#getString(int)

    public String randomize() {
        Cursor cursor;
        cursor =  this.db.query("tblnames ORDER BY RANDOM() LIMIT 1", new String[] { "*" }, null, null, null, null, null);
        if(cursor.moveToFirst()) {
            return cursor.getString(cursor.getColumnIndexOrThrow( "word" ));
        }
        return "";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my app I have a textView which contains real-time messages from my app,
I have a TextView which I fill with text from a string resources in
I have the following TextView in my XML layout file:- <TextView android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/autolink_test
I have textView in my cell and sometimes during tableView scroll some weird calls
I have a TextView which i set the text using setText(). In properties, I
I have TextView in RelativeLayout, which works properly: <TextView android:id=@+id/tv_client_in android:layout_width=wrap_content android:layout_height=wrap_content android:layout_above=@+id/tv_label_client_out android:layout_alignParentLeft=true
I have a TextView that will hold a styled, multiline string. This text is
I am trying to implement a android app. I have problems with TextView in
I have textview which contains urls like www.google.com . for this textview a have
I have service, widget and activity....widget and activity both have one textview which should

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.