Skip to content Skip to sidebar Skip to footer

Custom Baseadapter Edittext Click And Update Database In Button Click

I am going through a problem that is related to Custom BaseAdapter. First i have custom dialog as below As you can see there is three TextView , One EditText ( ) , One Button ( re

Solution 1:

May be this is not a perfect solution because you should consider redesigning your code when using ListView. ListView recycles and reuses it's Views when you scroll it up and down. As a result, you can observe like if you enable the ImageView in one row, the ImageView of other row will be also visible.

publicvoidclickHandler(View view) {
    if (view.getId() == R.id.orderQty) {
        LinearLayoutlayout= (LinearLayout) view.getParent().getParent();
        ImageViewimageView= (ImageView) layout.findViewById(R.id.save_on_id);
        imageView.setImageResource(R.drawable.save_on);
        imageView.setVisibility(ImageView.VISIBLE);
    }
}

Solution 2:

Try the base adapter like this way.

publicclasstes_adpextendsBaseAdapter{

    ArrayList<HashMap<String, String>> arry;

    privateLayoutInflater layoutInflater;
    Context context;
    HashMap<String, String> map;

    publictes_adp(Context context,  ArrayList<HashMap<String, String>> arry) {
        this.context = context;
        this.arry = arry;
        layoutInflater = LayoutInflater.from(context);
    }

    @Overridepublic int getCount() {
        // TODO Auto-generated method stubreturn arry.size();
    }

    @OverridepublicObjectgetItem(int position) {
        // TODO Auto-generated method stubreturn arry.get(position);
    }

    @Overridepublic long getItemId(int position) {
        // TODO Auto-generated method stubreturn position;
    }

    @OverridepublicViewgetView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        final ViewHolder holder;

        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.items, null);
            holder = newViewHolder();

            holder.price = (TextView)convertView.findViewById(R.id.price);
            holder.name = (TextView)convertView.findViewById(R.id.name);
            holder.qty = (EditText)convertView.findViewById(R.id.qty);
            holder.delete = (Button)convertView.findViewById(R.id.delete);
            holder.save = (Button)convertView.findViewById(R.id.save);

            convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();

        }

        map = arry.get(position);
        holder.price.setText(map.get("price"));
        holder.name.setText(map.get("name"));
        holder.qty.setText(map.get("qty"));
        holder.save.setVisibility(View.GONE);
       holder.save.setOnClickListener(newView.OnClickListener() {

            publicvoidonClick(View arg0) {
                // TODO Auto-generated method stub//Put your DB Code Here
                holder.save.setVisibility(View.GONE);
            }
        });

        holder.qty.setOnTouchListener(newOnTouchListener() {

            @OverridepublicbooleanonTouch(View arg0, MotionEvent arg1) {
                // TODO Auto-generated method stub

                holder.save.setVisibility(View.VISIBLE);
                returnfalse;
            }
        });


    return convertView;
}

    classViewHolder {

        Buttondelete,save;
        TextView name,price,qty;

    }
}

Post a Comment for "Custom Baseadapter Edittext Click And Update Database In Button Click"