-1

Value is automatically changed after user started typing in EditText.Value is automatically changed with initial value. Please Help me what is causing this issue

This layout is USed for adapter layout the complete layout file and adapter code is given below here is EditTextbox part that is causing issue

               <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:orientation="horizontal"
                    android:weightSum="2">
              <TextView
                    style="@style/booking_heading"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:text="Enter Amount" />
                <EditText
                    android:layout_width="0dp"
                    android:editable="true"
                    android:inputType="number"
                    android:layout_weight="1"
                    android:background="#fff"
                    android:padding="8dp"
                    android:text="00"
                    android:layout_height="match_parent"
                    android:id="@+id/booking_price" />
               </LinearLayout>

Code Of My Adapter class is

package com.visionprecis.vikrant;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.visionprecis.vikrant.DriverService.Booking;
import com.visionprecis.vikrant.LocationProvider.TrackingActivity;
import com.visionprecis.vikrant.StaticData.StaticInfo;

import java.util.ArrayList;
import java.util.HashMap;


public class BookingArrayAdapter extends ArrayAdapter {
    ArrayList<Booking> bookingArrayList;
    Context context;
    public BookingArrayAdapter(Context context, int resource,ArrayList<Booking> objects) {
        super(context, resource, objects);
        this.context=context;
        this.bookingArrayList=objects;
    }

    @Override
    public View getView(int position,  View convertView,ViewGroup parent) {

        LayoutInflater inflater=(LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        View view=inflater.inflate(R.layout.single_booking_layout,null);

        final Booking booking=bookingArrayList.get(position);

        TextView orgin=view.findViewById(R.id.booking_origin);
        TextView destination=view.findViewById(R.id.booking_destination);
        TextView status=view.findViewById(R.id.booking_status);
        final EditText price=view.findViewById(R.id.booking_price);
        Button trackbtn=view.findViewById(R.id.booking_track_btn);
        Button cancel=view.findViewById(R.id.booking_cancel);
        Button confirm=view.findViewById(R.id.booking_confirm);
        orgin.setText(booking.getOrigin().getAdress());
        destination.setText(booking.getDestination().getAdress());
        status.setText(booking.getStatus());
        price.setText(booking.getPrice());
        if(booking.getStatus().equals(StaticInfo.RIDE_REQUESTED)){
            confirm.setText("Send Amount");
            confirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   sendbidamound(booking,price.getText().toString());
                    Log.i(StaticInfo.TAG,"Price kis "+price.getText());
                }
            });
        }else if(booking.getStatus().equals(StaticInfo.RIDE_BID_PROVIDED)){
        //   confirm.setText("Confirmed");
            confirm.setText("Send Amount");
            confirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   sendbidamound(booking,price.getText().toString());
                    Log.i(StaticInfo.TAG,"Price kis "+price.getText());

                }
            });


        }

            trackbtn.setEnabled(true);
           trackbtn.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                   trackuser(booking.getUserid());
               }
           });

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                oncancelpressed(booking);
            }
        });

        return view;
    }

    private void trackuser(String userid) {
       Intent intent=new Intent(context,TrackingActivity.class);
        intent.putExtra("userid",userid);
        context.startActivity(intent);
    }

    private void oncancelpressed(Booking booking) {

        DatabaseReference reference=FirebaseDatabase.getInstance().getReference().child(StaticInfo.USER_BOOKING_REQUEST_TABLE)
                .child(booking.getUserid())
                .child(booking.getBookingid());
        reference.child("status").setValue(StaticInfo.RIDE_CANCELED).addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
           Toast.makeText(context,"Booking caceled Succcessfully",Toast.LENGTH_LONG).show();
            }
        });
    }

    private void sendbidamound(final Booking booking, final String price) {
        if(validateprice()){
            DatabaseReference userreference=FirebaseDatabase.getInstance().getReference().child(StaticInfo.USER_BOOKING_REQUEST_TABLE)
                    .child(booking.getUserid())
                    .child(booking.getBookingid());
            HashMap<String,Object> updatevalue=new HashMap<>();

            updatevalue.put("status",StaticInfo.RIDE_BID_PROVIDED);
            updatevalue.put("price",price);

            userreference.updateChildren(updatevalue).addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {

                    DatabaseReference driverreference=FirebaseDatabase.getInstance().getReference().child(StaticInfo.DRIVER_BOOKING_REQUEST_TABLE)
                            .child(booking.getDriverid())
                            .child(booking.getBookingid());
                    HashMap<String,Object> updatechild=new HashMap<>();
                    updatechild.put("status",StaticInfo.RIDE_BID_PROVIDED);
                    updatechild.put("price",price);
                    driverreference.updateChildren(updatechild).addOnCompleteListener(new OnCompleteListener<Void>() {
                        @Override
                        public void onComplete(@NonNull Task<Void> task) {
                            Toast.makeText(context,"Bid amount Placed Succcesfully Awaiting User Confirmation And You Will Be Notified back",Toast.LENGTH_LONG).show();
                            context.startActivity(new Intent(context,MainActivity.class));
                        }
                    });

                }
            });


        }

    }

    private boolean validateprice() {
        return true;
    }
}

Complete Layout Of The adapter is

        <!-- Begning Of child Layout  horizental-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:weightSum="2">

            <TextView
                style="@style/booking_heading"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="Origin" />

            <TextView
                style="@style/booking_value"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:id="@+id/booking_origin"
                android:text="Shimla Himachal Pradesh India" />
        </LinearLayout>
        <!-- End Of child Layout  horizental-->




        <!-- Begning Of child Layout  horizental-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:weightSum="2">

            <TextView
                style="@style/booking_heading"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="Destination" />

            <TextView
                style="@style/booking_value"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:id="@+id/booking_destination"
                android:text="Shimla Himachal Pradesh India" />
        </LinearLayout>
        <!-- End Of child Layout  horizental-->



        <!-- Begning Of child Layout  horizental-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:weightSum="2">

            <TextView
                style="@style/booking_heading"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="Ride Status" />

            <TextView
                style="@style/booking_value"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:id="@+id/booking_status"
                android:text=" " />
        </LinearLayout>
        <!-- End Of child Layout  horizental-->


        <!-- Begning Of child Layout  horizental-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:weightSum="2">

            <TextView
                style="@style/booking_heading"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:text="Enter Amount" />
            <EditText
                android:layout_width="0dp"
                android:editable="true"
                android:inputType="number"
                android:layout_weight="1"
                android:background="#fff"
                android:padding="8dp"
                android:layout_height="match_parent"
                android:id="@+id/booking_price" />

        </LinearLayout>

        <!-- End Of child Layout  horizental-->
        <!-- Begning Of child Layout  horizental-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:weightSum="2">

            <Button
                style="@style/booking_heading"
                android:textColor="#fff"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:background="#273e70"
                android:gravity="center"
                android:textStyle="bold"
                android:textAlignment="center"
                android:text="Cancel"
                android:layout_margin="4dp"
                android:id="@+id/booking_cancel"/>

            <Button
                style="@style/booking_heading"
                android:layout_width="0dp"
                android:textColor="#fff"
                android:layout_height="match_parent"
                android:background="#273e70"
                android:gravity="center"
                android:textStyle="bold"
                android:textAlignment="center"
                android:text="Confirm"
                android:layout_margin="4dp"
                android:id="@+id/booking_confirm" />
        </LinearLayout>
        <!-- End Of child Layout  horizental-->
<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Track User"
    android:layout_marginTop="8dp"
    android:textSize="22sp"
    android:enabled="false"
    android:id="@+id/booking_track_btn"
    />


    </LinearLayout>
    <!-- End  Of main Layout  vertical-->
</android.support.constraint.ConstraintLayout>

The Activity layout is

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".RequestedRidesListActivity">
<ListView
    android:layout_width="match_parent"
    android:id="@+id/booking_list_view"
    android:layout_height="wrap_content">

</ListView>
</android.support.constraint.ConstraintLayout>

Layout of the File isenter image description here

vikrant verma
  • 139
  • 1
  • 9

1 Answers1

0

Have you set textwatcher to your edit text ?

  • No i havn'y Done something like that . Although You can i have look at my adapter where iam setting value – vikrant verma Jan 08 '19 at 05:26
  • why you do this price.setText(booking.getPrice()); if you set your edit text can be edited ? it's pointless. Can you tell me what do you want to achieve ? do you want to catch user input in edit text or you want to set value to your edit text ?? – Daniel Wijono Jan 08 '19 at 05:31
  • I added the price that is bid by other user . here i want is that if Current Driver(User using this app) can change the amount and then this price will be send back to user – vikrant verma Jan 08 '19 at 05:34
  • Okay then you should put textwatcher to your edit text to detect your user input. This is the link how to do it (look in the answer) : https://stackoverflow.com/questions/4283062/textwatcher-for-more-than-one-edittext – Daniel Wijono Jan 08 '19 at 05:36
  • Well Problem Solved Textwatxher saved my day thankyou – vikrant verma Jan 08 '19 at 06:07