-1

I would like to receive information from a current item of the view through a button external, as it shows the image, the button is outside of the adapter. Can anyone help me?

Image : https://www.dropbox.com/s/ikdcjp7zmhyc1hm/image.png MainActivity.class

SimpleCardStackAdapter adapter = new SimpleCardStackAdapter(MainActivity.this);

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.mainlayout);
        new JSONParse().execute();
    }

    private class JSONParse extends AsyncTask<String, String, JSONObject> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            mCardContainer = (CardContainer) findViewById(R.id.layoutview);

            pDialog = new ProgressDialog(MainActivity.this);
            pDialog.setMessage("Obteniendo datos ...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        @Override
        protected JSONObject doInBackground(String... args) {
            JSONParser jParser = new JSONParser();
            JSONObject json = jParser.getJSONfromURL(url);
            return json;
        }
        @Override
        protected void onPostExecute(JSONObject json) {

            if(json != null){
                pDialog.dismiss();
                try {
                    // Getting JSON Array
                    user = json.getJSONArray(TAG_USER);
                    for (int i = 0; i < user.length(); i++) {
                        JSONObject c = user.getJSONObject(i);
                        id = c.getString(TAG_ID);
                        String image = c.getString(imagen);
                        adapter.add(new CardModel(id, "Sevilla", image));
                    }
                    //T
lovebtn = (Button) findViewById(R.id.lovebtn);
                    lovebtn.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub                          
                            Toast.makeText(getApplicationContext(), ""+item, Toast.LENGTH_SHORT).show();
                        }
                    });*/

                    mCardContainer.setAdapter(adapter);

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }else{
                pDialog.dismiss();
                Toast.makeText(getApplicationContext(), "Compruebe su conexión e inténtelo de nuevo más tarde", Toast.LENGTH_SHORT).show();
                //No hay datos 
            }

        }
    }

SimpleCardStackAdapter.class

public final class SimpleCardStackAdapter extends CardStackAdapter {

    public SimpleCardStackAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    public View getCardView(int position, CardModel model, View convertView, ViewGroup parent) {
        if(convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(getContext());
            convertView = inflater.inflate(R.layout.std_card_inner, parent, false);
            assert convertView != null;
        }

        int loader = R.drawable.ic_launcher;
        final ImageView image = (ImageView) convertView.findViewById(R.id.sp_image);

        ImageLoader imgLoader = new ImageLoader(mContext);

        ((TextView) convertView.findViewById(R.id.textView1)).setText(model.getTitle());
        ((TextView) convertView.findViewById(R.id.textView2)).setText(model.getDescription());
        imgLoader.DisplayImage(model.getImage(), loader, image);

        return convertView;
    }
}

CardModel

public class CardModel {

    private String title;
    private String description;
    //private Drawable cardImageDrawable;
    private String image;
    /*  private Drawable cardLikeImageDrawable;
    private Drawable cardDislikeImageDrawable;*/

    private OnCardDimissedListener mOnCardDimissedListener = null;

    private OnClickListener mOnClickListener = null;

    public interface OnCardDimissedListener {
        void onLike();
        void onDislike();
    }

    public interface OnClickListener {
        void OnClickListener();
    }

    /*public CardModel(String string, Drawable drawable) {
        this(null, null, null);
    }*/

    public CardModel(String title, String description, String image) {
        this.title = title;
        this.description = description;
        //this.cardImageDrawable = cardImage;
        this.image = image;
    }

    public CardModel(String title, String description, Bitmap cardImage) {
        this.title = title;
        this.description = description;
        //this.cardImageDrawable = new BitmapDrawable(null, cardImage);
    }

    public CardModel(HashMap<String, String> map) {
        this.title = title;
        this.description = description;
        this.image = image;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public String getImage(){
        return image;
    }

    public void setDescription(String description) {
        this.description = description;
    }


    public void setImage(String image) {
        this.image = image;
    }

Thank you very much to all, Greetings!

Adrian
  • 15
  • 4

1 Answers1

0

You can use the ListView's setOnItemClickListener to get the info, and the external button to present the interface displaying the details.

Let's just say:

ListView list = (ListView) findViewById(R.id.listview);
list.setOnItemClickListener(new AdapterView.onItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
      Object listItem = list.getItemAtPosition(position);
   } 
});

Referenced from this post

Community
  • 1
  • 1
Kyle Emmanuel
  • 2,193
  • 1
  • 15
  • 22