[英]Parse Json in list view and add click listener to each list item
I am making a streaming application and I am trying to parse JSON
in a list view dynamically , the response I get is name, photo and URL, I can't pass the URL on video view , to be more specific I want so when you click on the list item it should play the URL on video view , and I am also struggling with the photo. 我正在制作一个流应用程序,并且试图在列表视图中动态解析
JSON
,我得到的响应是名称,照片和URL,我无法在视频视图上传递该URL,更具体地说,当您想要单击列表项,它应该在视频视图上播放URL,而我也正在努力处理照片。
I succeeded by showing the JSON
object names in a list view but I don't have idea how to pass the URL on the video view and the photo , this is my code 我成功地在列表视图中显示了
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);
}
How to add click listener to each of the list items so when you click on them it should play the URL to the video view 如何将点击侦听器添加到每个列表项,因此当您单击它们时,应播放视频视图的URL
我建议使用RecyclerView和RecyclerViewAdapter。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.