gpt4 book ai didi

java - 分享意向安卓

转载 作者:行者123 更新时间:2023-11-29 07:51:41 26 4
gpt4 key购买 nike

我在 android 中创建了一个应用程序,它从数组列表中生成随机文本。现在我想分享 java 代码生成的文本...请帮帮我? 这是我的代码:

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


Resources res = getResources();
myString = res.getStringArray(R.array.myArray);

String q = myString[rgenerator.nextInt(myString.length)];

TextView tv = (TextView) findViewById(R.id.text1);
tv.setText(q);

Button home=(Button)findViewById(R.id.bottone);
home.setOnClickListener(new OnClickListener(){


public void onClick(View arg0) {

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "HERE GENERATE TEXT FROM ARRAY LIST");
startActivity(Intent.createChooser(shareIntent, "Condividi con..."));
}
});

}

}

最佳答案

试试这个

    super.onCreate(savedInstanceState);
setContentView(R.layout.sorella);


Resources res = getResources();
myString = res.getStringArray(R.array.myArray);

final String q = myString[rgenerator.nextInt(myString.length)];

TextView tv = (TextView) findViewById(R.id.text1);
tv.setText(q);

Button home=(Button)findViewById(R.id.bottone);
home.setOnClickListener(new OnClickListener(){


public void onClick(View arg0) {

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, q);
startActivity(Intent.createChooser(shareIntent, "Condividi con..."));
}
});

关于java - 分享意向安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20639700/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com