我有一个 Json 字符串。
每次打开我的应用程序并使用它们时,我都希望获得一个条目。在网上搜索,我创建了这样的东西:
ArrayList<HashMap<String, String>> Listads = new ArrayList<HashMap<String, String>>();
HashMap<String, String> mapads = new HashMap<String, String>();
String randomValue = null;
try {
for (adsTrend tr : objs.getTrends())
{
Log.i("ADS",
tr.getId() + " - " + tr.getLink() + " - "
+ tr.getType() + " - " + tr.getEnabled());
lv_arr[i] = tr.getId() + " - " + tr.getLink() + " - "
+ tr.getType() + " - " + tr.getEnabled();
i++;
mapads.put("id", tr.getId());
mapads.put("link", tr.getLink());
mapads.put("type", tr.getType());
mapads.put("enabled", tr.getEnabled());
Listads.add(mapads);
Random generator = new Random();
Object[] values = mapads.values().toArray();
randomValue = (String) values[generator.nextInt(values.length)];
}
Toast.makeText(SplashActivity.this,"this is my random value : "+randomValue,Toast.LENGTH_LONG).show();