如何从listview获取ImageLink(url)OnitemClickListener我的应用程序包含来自列表中服务器的图像我希望当用户点击行时我希望下一页在此活动中显示图像并分享到社交媒体我spand 3天在这个主题中我的代码在下面.....
我的代码是
private static final int REQ_SELECT_PHOTO = 1;
byte dataArray[] = new byte[1024];
ProgressDialog progressdialog;
CallbackManager callbackManager;
public static final int Progress_Dialog_Progress = 0;
private List<String> videoURLs = new ArrayList<String>();
ShareDialog shareDialog;
private Spinner spinner;
private ArrayList<String> spinnerdata;
private JSONArray result;
private boolean isImage = false;
// list view data
private static final String TAG = MainActivity.class.getSimpleName();
String url = "http://www.example.com/image.php";
private ProgressDialog pDialog;
private List<Model> movieList = new ArrayList<Model>();
private ListView listView;
private Image_Adapter adapter;
final Json_Data j_data = new Json_Data();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.image_activity);
callbackManager = CallbackManager.Factory.create();
spinnerdata = new ArrayList<String>();
spinner = (Spinner) findViewById(R.id.txtSpinner);
listView = (ListView) findViewById(R.id.list);
spinner.setOnItemSelectedListener(this);
listdata();
spinnerdata.add("Get Category");
adapter = new Image_Adapter(this, movieList);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
final TextView tv_id = (TextView) view.findViewById(R.id.imgtext);
}
});
pDialog = new ProgressDialog(this);
pDialog.setMessage("Loading...");
pDialog.setCanceledOnTouchOutside(false);
pDialog.show();
}
/****************************Getting ListView Data From Json************************************/
public void listdata()
{
JsonArrayRequest movieReq = new JsonArrayRequest(url,
new Response.Listener<JSONArray>()
{
@Override
public void onResponse(JSONArray response)
{
hidePDialog();
Log.e(TAG, response.toString());
for (int i = 0; i < response.length(); i++)
{
try
{
JSONObject obj = response.getJSONObject(i);
Model model = new Model();
String image_json= obj.getString("image");
String img_txt = obj.getString("txt");
Log.e(TAG,"Image"+image_json);
Log.e(TAG,"Image Text"+img_txt);
model.setThumbnailUrl(image_json);
model.setImg_text(img_txt);
movieList.add(model);
}
catch (JSONException e)
{
e.printStackTrace();
}
}
adapter.notifyDataSetChanged();
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
VolleyLog.d(TAG, "Error: " + error.getMessage());
hidePDialog();
}
});
AppController.getInstance().addToRequestQueue(movieReq);
}
public void onDestroy()
{
super.onDestroy();
hidePDialog();
}
private void hidePDialog()
{
if (pDialog != null)
{
pDialog.dismiss();
pDialog = null;
}
}
答案 0 :(得分:0)
首先在模型上添加返回函数
public String getImageUrl(){
return imageUrl;
}
OnItemClickListener
中的图片获取图片
String _URL = movieList.get(position).getImageUrl();