How to get the text from a random set textview?

alex

I just started with developing an android app. And this app is just a random quotes app. Now i am trying to get the text from a randomly quote textview. But it returns false.

public class DisplayQuoteActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_quote);

    final String[] listQuotes = {"Quote one","A million or so","Really don't care","Looks like it","Day is done!"};

    Random randGen = new Random();
    int rando = randGen.nextInt(5);

    TextView textQuote = (TextView) findViewById(R.id.viewQuote);
    textQuote.setText(listQuotes[rando]);
}


/** Called when an user wants to share a quote**/
public void shareQuote(View view){
    Log.d("test_app","Share Quote been pushed");
    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); 
    sharingIntent.setType("text/plain");
    String shareBody = this.getString(R.id.viewQuote);// "Here is the share content body";
    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
    startActivity(Intent.createChooser(sharingIntent, "Share via"));
}

}

shareBody seems to be false.

How do i get the text from the textview viewQuote??

Apoorv

Make textQuote a global variable and replace

 String shareBody = this.getString(R.id.viewQuote);

with

 String shareBody = textQuote.getText().toString();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to set the text color of TextView in code?

From Dev

Get Selected Text from TextView

From Dev

how to get text from textview using espresso

From Dev

How to get random text from lorem Ipsum in PHP?

From Dev

How do I get text from a calculated String to a TextView field?

From Dev

Android, How can I get text from TextView in OnClick

From Dev

How to get TextView text from a custom Spinner

From Dev

How to set position of text in TextView/EditText

From Dev

How to set the selected text background color of TextView

From Dev

How to get a random element from a Set in Scala

From Dev

How to Dynamically set text to TextView?

From Dev

How to get default text size from TextView on widget?

From Dev

How to get random element from a set in Swift?

From Dev

How to set the text of TextView based on Spinner?

From Dev

Get the text from a TextView

From Dev

How set text with accent in a textview?

From Dev

how to get language of text in a textview?

From Dev

Get random sentences from a set of text files

From Dev

Set Text from header textview widget

From Dev

How to set the text of a TextView?

From Dev

How to set text in a textview from a class that implements DialogFragment

From Dev

How can I set the text for a textview from an AsyncTask activity?

From Dev

How to get text from a textView in Haskell

From Dev

how to set a text of a textview from another activity

From Dev

How to get random text from lorem Ipsum in PHP?

From Dev

How to set the Text in textView to a text in .txt file

From Dev

how to get language of text in a textview?

From Dev

How can i get hyperlinks text from textview android?

From Dev

How to set formatted html text in a textview from String.xml?

Related Related

HotTag

Archive