我之前已经问过这个问题,但到目前为止,我仍然无法得到答案。 我正在创建一个引号App,引号将被发送到Whatsapp,imo,这是我的代码行。
int selector;
Button previous, next, send;
TextView display;
//List of random quotes
ArrayList<String> listOfRandomQuotes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inspiraionalquotes);
listOfRandomQuotes = new ArrayList<String>();
listOfRandomQuotes.add("Anger is the most important of passion. It affects nothing it touches and hurts the one who is possessed by it more than the one against whom it is directed.");
listOfRandomQuotes.add("No one can give you better advice than yourself.");
listOfRandomQuotes.add("The most wasted of all days is the one without laughter.");
listOfRandomQuotes.add("The man who persist in knocking will succed in entering.");
setButtonOnLongClickListener();
}
private void setButtonOnLongClickListener() {
Button sendButton = (Button)findViewById(R.id.send_button);
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_TEXT, "Need Help Here");
i.putExtra(Intent.EXTRA_SUBJECT, "My Subject");
Intent chooser = Intent.createChooser(i, "Can you Handle This");
// Verify that the intent will resolve to an activity
if (i.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
现在,如果单击发送按钮,将发送的消息“需要帮助在这里”............我想要的是生成的报价发送。
我还希望预览按钮为“BACK BUTTON”而不是随机选择引用... 这是上一个按钮的代码...
previous = (Button) findViewById(R.id.btnPrevious);
previous.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Random randomnumber = new Random();
selector = randomnumber.nextInt(277);
display.setText(listOfRandomQuotes.get(selector));
}
});
附件是完整的应用程序屏幕。enter image description here