When clicked on grid view how to send arralist(position) to another actvity

后端 未结 3 1066
不思量自难忘°
不思量自难忘° 2021-01-22 07:27

In this method I am receiving the ArrayList

        OkHttpHandler handler = new OkHttpHandler(MainActivity.this,new OkHttpHandler.MyInterface() {
           


        
3条回答
  •  旧时难觅i
    2021-01-22 08:21

    You can do this using following way

    You can set position of a grid item(here image) you click as a tag to imageview and then you can get the json object or single object from array list using above position and can send to another activity.

    holder.imageView.SetTag(position)
    holder.imageView.setOnClickListener(new View.OnClickListener() {
    
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            //Get your imageview here by using v.findviewbyid and get tag tag 
            //Like this
            //ImageView iv=(ImageView)v.findviewbyid(id of layout you mention to bind holder.imageView) 
             //Integer mPosition=(Integer)iv.getTag();
             //Then fetch that single object by using mPosition from your list and pass it  
            //JSONObject item = peoples.getJSONObject(mPosition);
            Log.d("OnImageButton", "Clicked");
            Intent intnt  =new Intent(mcontext, SingleViewActivity.class);
            //intnt.putExtra("Contact_list", item);
            mcontext.startActivity(intnt)  ; //This line raises error
            Toast.makeText(mcontext, "intent",
                Toast.LENGTH_LONG).show();
        }
    });
    

提交回复
热议问题