Anyone please tell me where and how should i correct this
public class Book_Activity extends 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
. 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
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
String[] Description = { "first", "second", "third"}
StringBuilder descriptionText = new StringBuilder();
for (String s: Description) {
descriptionText.append(s);
descriptionText.append(" ");
}
tvdescription.setText(descriptionText.toString().trim());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.