我正在制作一个流应用程序,并且试图在列表视图中动态解析JSON
,得到的响应是名称,照片和URL,我无法在视频视图上传递该URL,更具体地讲,我想要这样,当您单击列表项时,它应该在视频视图中播放URL,而我也在照片中苦苦挣扎。
我成功地在列表视图中显示了JSON
对象名称,但是我不知道如何在视频视图和照片上传递URL,这是我的代码
<pre>
public class CamerasJSON{
public String url;
public String photo;
public String name;
}
protected Void doInBackground(Void... arg0) {
Gson gson = new Gson();
HttpHandler sh = new HttpHandler();
JsonParser parser = new JsonParser();
// Making a request to url and getting response
String url = "https://test.com/index.php";
String jsonStr = sh.makeServiceCall(url);
CamerasJSON[] CamerasJSON =
gson.fromJson(jsonStr,CamerasJSON[].class);
for(int i=0; i<CamerasJSON.length; i++){
CamerasJSON cm = CamerasJSON[i];
String name = cm.name;
String photo = cm.photo;
String streamUrl = cm.url;
HashMap<String, String> contact = new HashMap<>();
contact.put("name", name);
contact.put("photo", photo);
contact.put("streamUrl", streamUrl);
contactList.add(contact);
Log.e(TAG, "KONTAKT : " + contactList);
}
Log.e(TAG, "Response from url: " + CamerasJSON.length);
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
ListAdapter adapter = new SimpleAdapter(FullscreenActivity.this, contactList,
R.layout.list_item, new String[]{ "name"},
new int[]{R.id.name});
lv.setAdapter(adapter);
}
如何将点击侦听器添加到每个列表项,因此当您单击它们时,应播放视频视图的URL
答案 0 :(得分:0)
我建议使用RecyclerView和RecyclerViewAdapter。