滑动以在列表视图中显示图像
我需要帮助。我试图使用滑动从服务器获取我的图像,但我不知道如何?请构建我的代码,以便Glide可以工作或给我任何其他可能的解决方案。我只想用Glide和JSON显示图像列表视图,JSON结果来自我的PHP脚本。除了图像以外,我能够获取其他数据。这是我的代码。我应该放置滑翔的地方?滑动以在列表视图中显示图像
public class list extends ListActivity {
private static final String TAG_POST= "posts";
private static final String TAG_ID="lecID";
private static final String TAG_NAME="lecName";
private static final String TAG_EMAIL="lecEmail";
private static final String TAG_PASS="lecPass";
private static final String TAG_IMAGE="image";
private static final String LECTURER_LIST_URL="http://system.com/list.php";
private JSONArray mComments =null;
private ArrayList<HashMap<String,String>> mcommentList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view);
ImageView imageView=(ImageView)findViewById(R.id.lec_Image);
//upload is the folder to store my image
String leciv="http://fypesystem.com/upload/";
Glide.with(this).load(leciv)
.thumbnail(0.5f)
.into(imageView);
您的帮助真的很感激。
更改这些行特别是URL。
ImageView imageView=(ImageView)findViewById(R.id.lec_Image);
//upload is the folder to store my image
String leciv="http://fypesystem.com/upload/9c419dd5659b0af4d14f642f454dcb07.jpg";
Glide.with(this).load(leciv)
.thumbnail(0.5f)
.into(imageView);
如果我写的上传/ 9c419dd5659b0af4d14f642f454dcb07.jpg它只会获取相同的图像? – Lawrence
你必须得到数组列表中的所有Url,然后逐个设置它们。告诉我你的json。 – Champandorid
已经显示在我上面的代码中。 – Lawrence
public static void LoadImage(Context cx,ImageView imageView,int demoImage,String url) {
if (!((Activity) cx).isFinishing()){
Glide.with(cx)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder(demoImage)
.into(imageView);
}
}
CX为背景demoImage是图像表示,直到你的形象是负载和网址,你从JSON获得的图像路径。
您必须制作一个自定义适配器,并将该适配器传递给您从json创建的列表以及要用于适配器和您的活动环境的布局。 然后,如果您使用的是listview,而不是listView的getView()函数,请添加此代码,其中url应该是您存储在列表中的值。Like this
String url = mcommentList.get(position).get(TAG_IMAGE );
myImageView应该从您通过适配器
Glide.with(上下文) .load(URL) .placeholder(R.drawable.ic_launcher) .into(myImageView)布局的图像;
可以通过这个链接,帮助
https://www.journaldev.com/10416/android-listview-with-custom-adapter-example-tutorial
你可以用添加您的问题JSON响应 –
不能加载文件夹URL到ImageView的 – Kuls