Soru & Cevap

Android Veritabanı Delete ...

30.07.2016 - 02:22

Merhaba ,

RecyclerView.Adapter ımda imagebutton'a tıklandığında tıklanan verinin ID alıp veritbanındaki DELETE methoduma göndermesini istiyorum ama ID yi alamadım ve aldıktan sonra neyi çalıştıracağım.. onBindViewHolder kod parçacığım

   @Override
    public void onBindViewHolder(final ViewHolder holder,final int position)
    {
         final WebItem s = list_garson.get(position);
        holder.txt_garson_isim.setText(list_garson.get(position).getLog_kullaniciIsim());
     //   holder.txt_garson_kullaniciAdi.setText(list_garson.get(position).getLog_kullaniciAdi());
     //   holder.txt_garson_sifre.setText(list_garson.get(position).getLog_sifre());

        holder.btn_garsonuSil.setImageResource(R.drawable.delete);
        holder.btn_garsonuSil.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {

                Bundle args = new Bundle();
                args.putInt("id", s.getKullanici_id());


            }
        });

    }

 

btn_garsonuSil e tıklandığında id yi alıp aşağıdaki gibi ASYNC nin çalışmasını istiyorum 

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

        private String id;

        addGarsonASYNC(String id){
            this.id = id;
        }



        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(Void... params)
        {
            SoapObject soapObject=new SoapObject(NameSpace.NAMESPACE, Methods.getGarsonAdd);

            soapObject.addProperty("id", id.toString ());

            soapSerializationEnvelope.dotNet = true;
            soapSerializationEnvelope.implicitTypes=true;
            soapSerializationEnvelope.setOutputSoapObject(soapObject);
            try
            {
                httpTransport.call(Actions.getGarsonAdd, soapSerializationEnvelope);
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            catch (XmlPullParserException e)
            {
                e.printStackTrace();
            }
            return null;
        }



        @Override
        protected void onPostExecute(Void aVoid) {
            return ;
        }
    }

 

7 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-57989-1451678910.jpg
serdarşen
31.07.2016 - 11:28

Merhaba Alperen, kodların tamamını test edemiyorum ama onClick metodunda biraz değişiklik yaptım.

Bundle iptal edildi, AsyncTask id parametresiyle oluşturup, execute ile çalıştırıldı. Kodları bir dene istersen.

   @Override
    public void onBindViewHolder(final ViewHolder holder,final int position)
    {
         final WebItem s = list_garson.get(position);
        holder.txt_garson_isim.setText(list_garson.get(position).getLog_kullaniciIsim());
     //   holder.txt_garson_kullaniciAdi.setText(list_garson.get(position).getLog_kullaniciAdi());
     //   holder.txt_garson_sifre.setText(list_garson.get(position).getLog_sifre());

        holder.btn_garsonuSil.setImageResource(R.drawable.delete);
        holder.btn_garsonuSil.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {

                ////Bundle args = new Bundle();
                ////args.putInt("id", s.getKullanici_id());
                new addGarsonASYNC(s.getKullanici_id.toString()).execute();

            }
        });

    }