Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 未在RecyclerView中显示的图像_Android_Android Recyclerview_Android Glide - Fatal编程技术网

Android 未在RecyclerView中显示的图像

Android 未在RecyclerView中显示的图像,android,android-recyclerview,android-glide,Android,Android Recyclerview,Android Glide,我想在我的应用程序中将URL中的图像显示为图库。 我已将此作为参考 但图像不会显示 这是我的厨房活动 public class GalleryActivity extends AppCompatActivity { String strServerResponse; ProgressDialog nDialog; private GalleryAdapter mAdapter; private RecyclerView recyclerView; private ArrayList<I

我想在我的应用程序中将URL中的图像显示为图库。 我已将此作为参考

但图像不会显示

这是我的厨房活动

public class GalleryActivity extends AppCompatActivity {

String strServerResponse;
ProgressDialog nDialog;
private GalleryAdapter mAdapter;
private RecyclerView recyclerView;
private ArrayList<Image> images;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gallery);

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

    images = new ArrayList<>();

    new NetCheck().execute();

}


private class NetCheck extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        nDialog = new ProgressDialog(GalleryActivity.this);
        nDialog.setMessage("Loading..");
        nDialog.setTitle("Please Wait");
        nDialog.setIndeterminate(false);
        nDialog.setCancelable(true);
        nDialog.show();
    }

    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        Log.e("Post exec calleld", "dfds");
        nDialog.dismiss();


        mAdapter = new GalleryAdapter(getApplicationContext(), images);

        RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getApplicationContext(), 2);
        recyclerView.setLayoutManager(mLayoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(mAdapter);

    }

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub

        try {

            HttpClient httpClient = new DefaultHttpClient();


            HttpPost httpRequest = new HttpPost(
                    uril);
            httpRequest.setHeader("Content-Type", "application/json");

            JSONObject json = new JSONObject();

            StringEntity se = new StringEntity(json.toString());
            se.setContentEncoding("UTF-8");
            se.setContentType("application/json");
            httpRequest.setEntity(se);
            HttpResponse httpRes = httpClient.execute(httpRequest);
            java.io.InputStream inputStream = httpRes.getEntity()
                    .getContent();
            InputStreamReader inputStreamReader = new InputStreamReader(
                    inputStream);
            BufferedReader reader = new BufferedReader(inputStreamReader);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            inputStream.close();
            strServerResponse = sb.toString();
            Log.e("Server Response", "" + strServerResponse.toString());
            if (strServerResponse != null) {
                try {

                    JSONObject jsonObj = new JSONObject(strServerResponse);
                    String status = jsonObj.getString("status");

                    if (status.equals("true")) {
                        String result = jsonObj.getString("images");
                        Log.e("images", "" + eee);
                        JSONArray arr1 = new JSONArray(result );
                        JSONObject jsonObj1 = arr1.getJSONObject(0);

                        Image image = new Image();
                        for (int i = 0; i < arr1.length(); i++) {

                            JSONObject jobjj11 = arr1
                                    .getJSONObject(i);

                            String name = jobjj11.optString("name");


                            Log.e("nurl",""+name);

                            image.setSmall(""+name);
                            images.add(image);
                            Log.e("images.tostring",""+images.toString());

                        }

                    }

                    else if (status.equals("false")){
                        Handler handler = new Handler(Looper.getMainLooper());
                        handler.post(
                                new Runnable() {
                                    @Override
                                    public void run() {
                                        AlertDialog alertDialog = new AlertDialog.Builder(
                                                GalleryActivity.this).create();
                                        alertDialog.setMessage("No imagesFound");
                                        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                                            public void onClick(DialogInterface dialog, int which) {
                                            }
                                        });

                                        alertDialog.show();
                                    }
                                }
                        );
                    }


                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else {

                Handler handler = new Handler(Looper.getMainLooper());
                handler.post(
                        new Runnable() {
                            @Override
                            public void run() {
                                AlertDialog alertDialog = new AlertDialog.Builder(
                                        GalleryActivity.this).create();
                                alertDialog.setMessage("Error Connecting to Server");
                                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                    }
                                });

                                alertDialog.show();
                            }
                        });
                //Log.e("ServiceHandler", "Couldn't get any data from the url");

            }

        } catch (UnsupportedEncodingException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        } catch (ClientProtocolException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        } catch (IOException e) {

            // TODO Auto-generated catch block

            e.printStackTrace();

        }

        return null;

    }
}
公共类GalleryActivity扩展了AppCompatActivity{
字符串strserver响应;
恩迪亚洛;
私人厨房适配器;
私人回收站;
私有数组列表图像;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gallery);
recyclerView=(recyclerView)findViewById(R.id.recycler\u视图);
images=newarraylist();
新建NetCheck().execute();
}
私有类NetCheck扩展了异步任务{
@凌驾
受保护的void onPreExecute(){
//TODO自动生成的方法存根
super.onPreExecute();
nDialog=新建进度对话框(GalleryActivity.this);
nDialog.setMessage(“加载…”);
nDialog.setTitle(“请稍候”);
nDialog.SetUndeterminate(假);
nDialog.setCancelable(真);
nDialog.show();
}
@凌驾
受保护的void onPostExecute(void结果){
//TODO自动生成的方法存根
super.onPostExecute(结果);
Log.e(“Post exec calleld”、“dfds”);
nDialog.discouse();
mAdapter=newGalleryAdapter(getApplicationContext(),images);
RecycleView.LayoutManager mLayoutManager=新的GridLayoutManager(getApplicationContext(),2);
recyclerView.setLayoutManager(mLayoutManager);
setItemAnimator(新的DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
}
@凌驾
受保护的Void doInBackground(Void…参数){
//TODO自动生成的方法存根
试一试{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost httpRequest=新的HttpPost(
乌里尔);
setHeader(“内容类型”、“应用程序/json”);
JSONObject json=新的JSONObject();
StringEntity se=新的StringEntity(json.toString());
se.setContentEncoding(“UTF-8”);
setContentType(“应用程序/json”);
httpRequest.setEntity(se);
HttpResponse httpRes=httpClient.execute(httpRequest);
java.io.InputStream InputStream=httpRes.getEntity()
.getContent();
InputStreamReader InputStreamReader=新的InputStreamReader(
输入流);
BufferedReader reader=新的BufferedReader(inputStreamReader);
StringBuilder sb=新的StringBuilder();
字符串行=null;
而((line=reader.readLine())!=null){
sb.追加(第+行“\n”);
}
inputStream.close();
strServerResponse=sb.toString();
Log.e(“服务器响应”,“strServerResponse.toString());
if(strServerResponse!=null){
试一试{
JSONObject jsonObj=新的JSONObject(strServerResponse);
String status=jsonObj.getString(“status”);
if(status.equals(“true”)){
字符串结果=jsonObj.getString(“图像”);
Log.e(“图像”和“+eee”);
JSONArray arr1=新JSONArray(结果);
JSONObject jsonObj1=arr1.getJSONObject(0);
图像=新图像();
对于(int i=0;ipublic class GalleryAdapter extends RecyclerView.Adapter<GalleryAdapter.MyViewHolder> {

private List<Image> images;
private Context mContext;

public class MyViewHolder extends RecyclerView.ViewHolder {


    public ImageView thumbnail;

    public MyViewHolder(View view) {
        super(view);
        thumbnail = (ImageView) view.findViewById(R.id.thumbnail);
    }
}


public GalleryAdapter(Context context, List<Image> images) {
    Log.e("ingalleryadapter", "aaddd");
    mContext = context;
    this.images = images;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.gallery_thumbnail, parent, false);

    return new MyViewHolder(itemView);
}

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    Image image = images.get(position);

    Glide.with(mContext).load(image.getSmall())
            .thumbnail(0.5f)
            .crossFade()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .into(holder.thumbnail);
}

@Override
public int getItemCount() {
    return images.size();
}

public interface ClickListener {
    void onClick(View view, int position);

    void onLongClick(View view, int position);
}

public static class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {

    private GestureDetector gestureDetector;
    private GalleryAdapter.ClickListener clickListener;

    public RecyclerTouchListener(Context context, final RecyclerView recyclerView, final GalleryAdapter.ClickListener clickListener) {
        this.clickListener = clickListener;
        gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onSingleTapUp(MotionEvent e) {
                return true;
            }

            @Override
            public void onLongPress(MotionEvent e) {
                View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
                if (child != null && clickListener != null) {
                    clickListener.onLongClick(child, recyclerView.getChildPosition(child));
                }
            }
        });
    }

    @Override
    public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {

        View child = rv.findChildViewUnder(e.getX(), e.getY());
        if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
            clickListener.onClick(child, rv.getChildPosition(child));
        }
        return false;
    }

    @Override
    public void onTouchEvent(RecyclerView rv, MotionEvent e) {
    }

}
}
Glide
    .with(context)
    .load(UsageExampleListViewAdapter.eatFoodyImages[0])
    .override(600, 200) // resizes the image to these dimensions (in pixel). does not respect aspect ratio
    .into(imageViewResize);