我刚开始开发一个android应用程序。而这个应用程序只是一个随机报价应用程序。 现在我试图从随机引用textview中获取文本。但它返回false。如何从随机设置textview中获取文本?
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似乎是假的。
如何从textview viewQuote获取文本?
TX,提出您的建议通过工作'字符串shareBody = textQuote.getText()的toString();',使textQuote一个全局变量 – alex
欢迎您。如果这有助于你接受答案。 – Apoorv
顺便说一句,你有什么建议采取哪种策略来结合500个不同的报价和每周增加的报价?我应该使用文本文件还是数据库?在此先感谢 – alex