[英]how do I toast array values from getter in my object?
My JSON Array
is of this format and I am trying to toast
the user_review_ids
values - 63,59,62
. 我
JSON Array
是这种格式的,我想toast
的user_review_ids
值- 63,59,62
。 I keep getting what I believe is a reference
to the values, rather than the values themselves - I get in toast
, '[Ljava.lang.String.;@41c19f...
stuff like that. 我一直得到的是对值的
reference
,而不是对值本身的reference
-我进来toast
, '[Ljava.lang.String.;@41c19f...
东西。
From what I read I thought methods like copyOf
or clone()
might do the trick but no joy. 从我的阅读中,我认为像
copyOf
或clone()
可能会成功,但没有乐趣。
My JSON Array
is in this format, on my server: 我的服务器上的
JSON Array
是这种格式:
[{"cat_name":"name1","user_review_ids":[63,59,62],
"private_review_ids":[],"public_review_ids":["9999"],"user_personal_count":3,
"private_count":0,"public_count":1}]
When I try to toast
any of the values for user_personal_count
, private_count
, public_count
, I have no problems, just the array. 当我尝试
toast
user_personal_count
, private_count
, public_count
任何值时,我都没有问题,只是数组。
Here is my code in the Category
object: 这是我在
Category
对象中的代码:
String cat_name;
String [] user_review_ids;
String user_personal_count;
String private_count;
String public_count;
public Category() {
}
public String getName() {
//return the value of the JSON key named cat_name in php file
return cat_name;
}
public String[] getUserReviewIds() {
//return the value of the JSON key named user_personal_count in php file
// return user_personal_count;
return user_review_ids;
}
public String getUserPersonalCount() {
//return the value of the JSON key named user_personal_count in php file
return user_personal_count;
}
public String getPrivateCount() {
//return the value of the JSON key named private_count in php file
return private_count;
}
public String getPublicCount() {
return public_count;
}
}
And the function that toasts the value, which is in another class: 带有该值的函数,该函数在另一个类中:
@Override
public void onContactSelected(Category category) {
Toast.makeText(getApplicationContext(), "Selected: " + category.getUserReviewIds(), Toast.LENGTH_LONG).show();
}
Do: 做:
Arrays.toString(category.getUserReviewIds())
in your Toast as explained here . 在祝酒词作为解释在这里 。
String[] array = new String[] {"John", "Mary", "Bob"}; System.out.println(Arrays.toString(array));
So your method should be like that: 所以你的方法应该是这样的:
@Override
public void onContactSelected(Category category) {
Toast.makeText(getApplicationContext(), "Selected: " + Arrays.toString(category.getUserReviewIds()), Toast.LENGTH_LONG).show();
}
I don't know what your app is about but Toasts are definitively not the nicest way to display something to the user. 我不知道您的应用程序是关于什么的,但是Toast绝对不是向用户显示内容的最佳方法。
Otherwise, to answer your question, yes you're displaying the reference to the array and not the array itself, that why you have @41c19f
否则,要回答您的问题,是的,您正在显示对数组的引用,而不是数组本身,这就是为什么要使用
@41c19f
Use String.join(delimiter,stringArray);
使用
String.join(delimiter,stringArray);
. 。 At the place of
delimiter
you can use comma( ,
) or something else. 在的地方
delimiter
,你可以用逗号( ,
)或别的东西。
@Override
public void onContactSelected(Category category) {
Toast.makeText(getApplicationContext(), "Selected: " + String.join(",",category.getUserReviewIds()), Toast.LENGTH_LONG).show();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.