[英]Cannot resolve method 'setText(java.lang.String[])'
Anyone please tell me where and how should i correct this任何人请告诉我应该在哪里以及如何纠正这个
public class Book_Activity extends AppCompatActivity {公共类 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);
You are passing Description as string []
tp a tvdescription
text view but text view only support to string
.您将 Description 作为
string []
tp 传递给tvdescription
文本视图,但文本视图仅支持string
。 That was an issue.那是个问题。
So, first you need to correct that process.所以,首先你需要纠正这个过程。 For example, you need to identify which data need to show in the text view from the string array that you used.
例如,您需要从您使用的字符串数组中确定需要在文本视图中显示哪些数据。
OR,或者,
If you want to show string array on text view you should set that string array to string.如果要在文本视图上显示字符串数组,则应将该字符串数组设置为字符串。 For that, you could try below solutions,
为此,您可以尝试以下解决方案,
Solution 1解决方案1
String[] Description = { "first", "second", "third"}
// Print as [first, second, third ]
tvdescription.setText(Arrays.toString(Description));
// Print as first, second, third
tvdescription.setText(Arrays.toString(Description).replaceAll("\\[|\\]", ""));
Solution 2解决方案2
String[] Description = { "first", "second", "third"}
StringBuilder descriptionText = new StringBuilder();
for (String s: Description) {
descriptionText.append(s);
descriptionText.append(" ");
}
tvdescription.setText(descriptionText.toString().trim());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.