大佬教程收集整理的这篇文章主要介绍了无法解析方法“setText(java.lang.String[])”,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
请告诉我应该在哪里以及如何纠正这个问题
公共类 Book_Activity 扩展了 AppCompatActivity {
private TextVIEw tvtitle,tvdescription,tvcategory;
private ImageVIEw img;
@OverrIDe
protected voID onCreate(Bundle savedInstanceStatE) {
super.onCreate(savedInstanceStatE);
setContentVIEw(R.layout.activity_book);
tvtitle = findVIEwByID(R.ID.txttitlE);
TextVIEw tvdescription = findVIEwByID(R.ID.txtdes);
tvcategory = findVIEwByID(R.ID.txtcat);
img = findVIEwByID(R.ID.bookthumbnail);
// RecIEve data
Intent intent = geTintent();
String title = intent.getExtras().getString("title");
String category = intent.getExtras().getString("category");
String[] Description = intent.getExtras().getStringArray("Description");
int image = intent.getExtras().geTint("thumbnail") ;
// SetTing values
tvtitle.setText(titlE);
tvcategory.setText(category);
tvdescription.setText(Description);
img.setimageresource(imagE);
您将描述作为 String []
tp tvdescription
文本视图传递,但文本视图仅支持 String
。那是个问题。
因此,首先您需要更正该过程。例如,您需要从您使用的字符串数组中确定需要在文本视图中显示哪些数据。
或,
如果您想在文本视图中显示字符串数组,您应该将该字符串数组设置为字符串。为此,您可以尝试以下解决方案,
解决方案 1
String[] Description = { "first","second","third"}
// Print as [first,second,third ]
tvdescription.setText(Arrays.toString(Description));
// Print as first,third
tvdescription.setText(Arrays.toString(Description).replaceAll("\\[|\\]",""));
解决方案 2
String[] Description = { "first","third"}
StringBuilder descriptiontext = new StringBuilder();
for (String s: Description) {
descriptiontext.append(s);
descriptiontext.append(" ");
}
tvdescription.setText(descriptiontext.toString().trim());
以上是大佬教程为你收集整理的无法解析方法“setText(java.lang.String[])”全部内容,希望文章能够帮你解决无法解析方法“setText(java.lang.String[])”所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。