单击后Android适配器项更改

时间:2016-04-19 08:52:55

标签: android

我有一个可以容纳人类的自定义适配器。这些人具有一些特征。我想要的是当我点击其中一个人,功能被改变。 (就像WhatsApp中的新消息一样)。自定义适配器类:

    public class GecmisInsanAdapter extends ArrayAdapter<Insan> {

    ArrayList<Insan> objects;
    ArrayList<Insan> kokobjects;
    int resource;
    Context context;
    LayoutInflater lala;
    private DisplayImageOptions options;
    Filter insanfilter = new Filter() {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            FilterResults results = new FilterResults();
            if (constraint == null || constraint.length() == 0) {
                results.values = objects;
                results.count = objects.size();
            } else {
                ArrayList<Insan> sonuclistesi = new ArrayList<>();
                for (Insan i : kokobjects) {
                    if (i.getName().contains(constraint.toString())) {
                        sonuclistesi.add(i);
                    }
                }
                results.values = sonuclistesi;
                results.count = sonuclistesi.size();
            }
            return results;
        }

        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {
            if (results.count == 0) {
                notifyDataSetInvalidated();
            } else {
                objects = (ArrayList<Insan>) results.values;
                notifyDataSetChanged();
            }
        }
    };


    private String sharedPrefBilinmeyenPathAl() {
        SharedPreferences sP = context.getSharedPreferences("programisleyis", Context.MODE_PRIVATE);
        return sP.getString("bilinmeyenresimpath", "defaultbilinmeyenresimpath");
    }

    public GecmisInsanAdapter(Context context, int resource, ArrayList<Insan> objects) {
        super(context, resource, objects);
        this.objects = objects;
        kokobjects = objects;
        this.resource = resource;
        this.context = context;
        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.ins)
                .showImageForEmptyUri(R.mipmap.soruisareti)
                .showImageOnFail(R.mipmap.soruisareti)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .displayer(new CircleBitmapDisplayer(Color.WHITE, 0))
                .build();
        lala = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        final InsanHolder insanholder;
        final int pozisyon = position;
        if (convertView == null) {
            convertView = lala.inflate(resource, null);
            insanholder = new InsanHolder();
            insanholder.insanresmi = (ImageView) convertView.findViewById(R.id.imgIcon);
            insanholder.insanadi = (TextView) convertView.findViewById(R.id.txtTitle);
            insanholder.insandurumu = (TextView) convertView.findViewById(R.id.textView20);
            insanholder.esasbolge = (LinearLayout) convertView.findViewById(R.id.esasbolge);
            insanholder.yenimesajvarmi = (FrameLayout) convertView.findViewById(R.id.yenimesajvarmi);
            insanholder.yenimesajsayisi = (TextView) convertView.findViewById(R.id.kacyenimesaj);
            convertView.setTag(insanholder);
        } else {
            insanholder = (InsanHolder) convertView.getTag();
        }
        if(objects.get(position).getResmiacik().equals("degil")){
            String bilinmeyenpath = sharedPrefBilinmeyenPathAl();
            Bitmap b = BitmapFactory.decodeFile(bilinmeyenpath);
            insanholder.insanresmi.setImageBitmap(b);
            insanholder.insanadi.setText("??????");
            insanholder.insandurumu.setText("?????????????");
            if(objects.get(position).getYenimesajvarmi().equals("var")){
                insanholder.yenimesajvarmi.setVisibility(View.VISIBLE);
                insanholder.yenimesajsayisi.setText(objects.get(position).getKacyenimesaj());
            }

        }else if(objects.get(position).getResmiacik().equals("acik")) {
            String decodedImgUri = Uri.fromFile(new File(objects.get(position).getResimpath())).toString();
            ImageLoader.getInstance().displayImage(decodedImgUri, insanholder.insanresmi, options);
            insanholder.insanadi.setText(objects.get(position).getName());
            insanholder.insandurumu.setText(objects.get(position).getDurum());
            if(objects.get(position).getYenimesajvarmi().equals("var")){
                insanholder.yenimesajvarmi.setVisibility(View.VISIBLE);
                insanholder.yenimesajsayisi.setText(objects.get(position).getKacyenimesaj());
            }
        }
        if(objects.get(position).getBandurumu().equals("evet")){
            insanholder.esasbolge.setBackgroundColor(Color.BLUE);
        }
        /*ServerGuncelDurumuAl sGDA = new ServerGuncelDurumuAl();
        try {
            holder.text2.setText( sGDA.execute(objects.get(position).getId()).get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }*/
        //holder.reportbutonu.setOnClickListener()
        insanholder.esasbolge.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                objects.get(pozisyon).setKacyenimesaj("0");
                objects.get(pozisyon).setYenimesajvarmi("yok");
                listeyiYenile();
                String name = objects.get(pozisyon).getName();
                String id = objects.get(pozisyon).getId();
                String durum = objects.get(pozisyon).getDurum();
                String resimpath = objects.get(pozisyon).getResimpath();
                String bandurumu = objects.get(pozisyon).getBandurumu();
                String faceprofilurl = objects.get(pozisyon).getFaceprofilur();
                Intent intent = new Intent(context, Mesajlasma.class);
                intent.putExtra("faceprofilurl" , faceprofilurl);
                intent.putExtra("bandurumu" , bandurumu);
                intent.putExtra("karsiserverid", id);
                intent.putExtra("karsiisim", name);
                intent.putExtra("karsidurum" ,durum);
                intent.putExtra("karsiresimpath" , resimpath);
                intent.putExtra("intentname", "GecmisInsanAdapter");
                context.startActivity(intent);
            }
        });
        /*holder.image1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("tago", "kullanıcı resmi tıklandı");
                Dialog dialog = new Dialog(context);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(R.layout.dialogkullanici);
                dialog.getWindow().setDimAmount(0.7f);
                dialog.show();
                ImageButton imageb1, imageb2, imageb3, imageb4;
                imageb1 = (ImageButton) dialog.findViewById(R.id.imageButton15);
                imageb2 = (ImageButton) dialog.findViewById(R.id.imageButton16);
                imageb3 = (ImageButton) dialog.findViewById(R.id.imageButton17);
                imageb4 = (ImageButton) dialog.findViewById(R.id.imageButton18);
                try {
                    imageb1.setImageBitmap(new urldenResimm().execute(objects.get(pozisyon).getUrl()).get());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }
                imageb2.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        Intent intent = new Intent(context, Mesajlasma.class);
                        try {
                            icon = new urldenResimm().execute(objects.get(pozisyon).getUrl()).get();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        } catch (ExecutionException e) {
                            e.printStackTrace();
                        }
                        intent.putExtra("isim", objects.get(pozisyon).getName());
                        intent.putExtra("id", objects.get(pozisyon).getId());
                        intent.putExtra("resimurl", objects.get(pozisyon).getUrl());
                        intent.putExtra("intentname", "InsanAdapter");
                        Bundle bundle = new Bundle();
                        bundle.putParcelable("kullaniciresmi", icon);
                        intent.putExtra("kullaniciresmi", bundle);
                        context.startActivity(intent);
                    }
                });

                imageb3.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        Log.i("tago", "like etme işlemi başlatıldı");
                    }
                });
                imageb4.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        Log.i("tago", "kullanici report etme işlemi başlatıldı");
                    }
                });
            }

        });

*/
        return convertView;
    }

    private void listeyiYenile() {
        notifyDataSetChanged();
    }


    private Bitmap getCircleBitmap(Bitmap b) {
        final Bitmap output = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ARGB_8888);
        final Canvas canvas = new Canvas(output);
        final int color = Color.RED;
        final Paint paint = new Paint();
        final Rect rect = new Rect(0, 0, b.getWidth(), b.getHeight());
        final RectF rectf = new RectF(rect);

        paint.setAntiAlias(true);
        paint.setColor(color);
        canvas.drawARGB(0, 0, 0, 0);
        canvas.drawOval(rectf, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

        canvas.drawBitmap(b, rect, rect, paint);
        return output;
    }

    public Filter getFilter() {
        if (insanfilter==null){
            Log.i("tago" , "gecmis insanfilter bos");
        }
        return insanfilter;
    }

    static class InsanHolder {
        public ImageView insanresmi;
        public TextView insanadi, insandurumu , yenimesajsayisi;
        public LinearLayout esasbolge;
        public FrameLayout yenimesajvarmi;
    }

这些人在&#34;对象&#34; ArrayList来自构造函数。它有&#34; yenimesajvarmi&#34;和&#34; kacyenimesaj&#34;变量。在getView方法&#34; insanholder.esasbolge.setOnClickListener(新的View.OnClickListener()&#34;部分,用户点击这个区域并意图新的类。我希望当用户回来时这些变量被更改。我怎样才能提供它??

&#34; yenimesajvarmi&#34; =&#34; isthereanynewmessage&#34;。

0 个答案:

没有答案