用户开始输入EditText
后,值会自动更改。值会自动更改为初始值。
请帮助我,导致此问题的原因
此布局用于适配器布局,完整的布局文件和适配器代码如下所示,这是引起问题的EditTextbox部分
<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>
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;
}
}
<!-- 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>
<?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>
答案 0 :(得分:0)
您是否已将textwatcher设置为您的编辑文本?