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??
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.
Comments