EditText无法获取

时间:2016-09-02 02:48:34

标签: android

我的editText使用上一页的getExtra和Im处理的页面进行编辑,因此当我执行该过程时,由于editText导致它读取android.support.v7.widget.AppCompatEditText而不是editText中的字符串,因此它什么都不做。请帮帮我们。谢谢。 :)

AcceptCars.java

public class AcceptCars implements Serializable {


@SerializedName("acceptedID")
public int acceptedID;

@SerializedName("acceptDate")
public String acceptDate;

@SerializedName("acceptTime")
public String acceptTime;

@SerializedName("acceptModel")
public String acceptModel;

@SerializedName("acceptType")
public String acceptType;

@SerializedName("acceptImage")
public String acceptImage;

@SerializedName("acceptFuelType")
public String acceptFuelType;

@SerializedName("acceptPlateNumber")
public String acceptPlateNumber;

@SerializedName("acceptCarOwner")
public String acceptCarOwner;

@SerializedName("acceptResLocation")
public String acceptResLocation;

@SerializedName("acceptCapacity")
public String acceptCapacity;

@SerializedName("renter")
public String renters;

@SerializedName("acceptPrice")
public String acceptPrice;

@SerializedName("acceptDestination")
public String acceptDestination;


}

AcceptedActivity.java(1stclass)

public class AcceptedActivity extends AppCompatActivity {

TextView tvresID, tvCarModel, tvCarType, tvCapacity, tvFuelType, tvPlateNumber, tvResDate, tvResTime,tvResLocation,tvPoster,tvRenter, tvDestination, tvPrice;
ImageView ivImage;
private static Button btnCancel;
private static Button btnReSched;
private ArrayList<AcceptCars> carList;
private FunDapter<AcceptCars> adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_accepted);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    onButtonClick();


    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    final AcceptCars Cars = (AcceptCars) getIntent().getSerializableExtra("cars");
    ImageLoader.getInstance().init(UILConfig.config(AcceptedActivity.this));
    tvCarModel = (TextView)findViewById(R.id.tvCarModel);
    tvCarType = (TextView)findViewById(R.id.tvCarType);
    tvCapacity = (TextView)findViewById(R.id.tvCapacity);
    tvFuelType = (TextView)findViewById(R.id.tvFuelType);
    tvPoster = (TextView)findViewById(R.id.tvPoster);
    tvPlateNumber = (TextView)findViewById(R.id.tvPlateNumber);
    tvResDate = (TextView) findViewById(R.id.tvResDate);
    tvResTime = (TextView) findViewById(R.id.tvResTime);
    tvResLocation = (TextView) findViewById(R.id.tvResLocation);
    tvPrice = (TextView) findViewById(R.id.tvPrice);
    tvDestination = (TextView) findViewById(R.id.tvDestination);
    tvRenter = (TextView) findViewById(R.id.tvRenter);
    tvresID = (TextView) findViewById(R.id.tvresID);
    ivImage = (ImageView)findViewById(R.id.ivImg);

    if (Cars != null) {
        tvresID.setText(""+ Cars.acceptedID);
        tvCarModel.setText(Cars.acceptModel);
        tvCarType.setText(Cars.acceptType);
        tvCapacity.setText(Cars.acceptCapacity);
        tvFuelType.setText(Cars.acceptFuelType);
        tvPlateNumber.setText(Cars.acceptPlateNumber);
        tvResDate.setText(Cars.acceptDate);
        tvResTime.setText(Cars.acceptTime);
        tvResLocation.setText(Cars.acceptResLocation);
        tvPoster.setText(Cars.acceptCarOwner);
        tvRenter.setText(Cars.renters);
        tvDestination.setText(Cars.acceptDestination);
        tvPrice.setText(Cars.acceptPrice);

        ImageLoader.getInstance().displayImage(Cars.acceptImage, ivImage);
    }

}

public void onButtonClick(){
    btnCancel = (Button) findViewById(R.id.btnCancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder a_cancel = new AlertDialog.Builder(AcceptedActivity.this);
            a_cancel.setMessage("Are you sure you want to cancel this rent?")
                    .setCancelable(false)
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            HashMap postData = new HashMap();
                            postData.put("acceptedID",""+tvresID.getText().toString());


                            PostResponseAsyncTask taskPost = new PostResponseAsyncTask(AcceptedActivity.this, postData, new AsyncResponse() {
                                @Override
                                public void processFinish(String s) {
                                    if (s.contains("success")){
                                        Toast.makeText(AcceptedActivity.this, "Rent Cancelled", Toast.LENGTH_SHORT).show();
                                        Intent in = new Intent(AcceptedActivity.this,RenterTabs.class);
                                        startActivity(in);
                                        finish();
                                    }else{
                                        Toast.makeText(AcceptedActivity.this, "Error", Toast.LENGTH_SHORT).show();
                                    }
                                }
                            });
                            taskPost.execute("http://carkila.esy.es/cancellation.php");
                        }
                    })
                    .setNegativeButton("No", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
            AlertDialog alert = a_cancel.create();
            alert.setTitle("Cancel");
            alert.show();
        }
    });

    btnReSched = (Button) findViewById(R.id.reSched);
    btnReSched.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder a_Resched = new AlertDialog.Builder(AcceptedActivity.this);
            a_Resched.setMessage("Are you sure you want to Reschedule this rent?")
                    .setCancelable(false)
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            final AcceptCars Cars = (AcceptCars) getIntent().getSerializableExtra("cars");
                            Intent in2 = new Intent (AcceptedActivity.this,ReSchedClick.class);
                            in2.putExtra("e1",Cars.acceptModel);
                            in2.putExtra("e2",Cars.acceptType);
                            in2.putExtra("e3",Cars.acceptCapacity);
                            in2.putExtra("e4",Cars.acceptPlateNumber);
                            in2.putExtra("e5",Cars.acceptDate);
                            in2.putExtra("e6",Cars.acceptTime);
                            in2.putExtra("e7",Cars.acceptResLocation);
                            in2.putExtra("e8",Cars.acceptCarOwner);
                            in2.putExtra("e9",Cars.renters);
                            in2.putExtra("e10",Cars.acceptDestination);
                            in2.putExtra("e11",Cars.acceptPrice);
                            in2.putExtra("e12",Cars.acceptedID);
                            startActivity(in2);
                        }
                    })
                    .setNegativeButton("No", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
            AlertDialog alert1 = a_Resched.create();
            alert1.setTitle("Reschedule");
            alert1.show();
        }
    });

}

ReschedClick.java(2ndclass)

public class ReSchedClick extends AppCompatActivity implements View.OnClickListener {
TextView tvCarModel, tvCarType, tvCapacity, tvFuelType, tvPlateNumber, tvPoster, tvPrice, tvacceptedID;
EditText etResDate, etResTime, etReturnDate, etReturnTime, etResLocation, etDestination;
ImageView ivImage;
int year_x,month_x,day_x;
final String TAG = this.getClass().getName();
int hour_x,minute_x;
GalleryPhoto galleryPhoto;
Button btnResched;
String e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11, e12;


static final int DIALOG_ID = 0;
static final int DIALOG_ID2 =2;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_re_sched_click);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    showDialogOnButtonClick();


    galleryPhoto = new GalleryPhoto(getApplicationContext());

    ImageLoader.getInstance().init(UILConfig.config(ReSchedClick.this));

    final Calendar cal = Calendar.getInstance();

    year_x = cal.get(Calendar.YEAR);
    month_x = cal.get(Calendar.MONTH);
    day_x = cal.get(Calendar.DAY_OF_MONTH);


    etResLocation = (EditText) findViewById(R.id.etPickup);
    etDestination= (EditText) findViewById(R.id.etDestination);

    tvCarModel = (TextView)findViewById(R.id.tvCarModel);
    tvCarType = (TextView)findViewById(R.id.tvCarType);
    tvCapacity = (TextView)findViewById(R.id.tvCapacity);
    tvFuelType = (TextView)findViewById(R.id.tvFuelType);
    tvPoster = (TextView)findViewById(R.id.tvPoster);
    tvPlateNumber = (TextView)findViewById(R.id.tvPlateNumber);
    ivImage = (ImageView)findViewById(R.id.ivImage);
    tvPrice = (TextView) findViewById(R.id.tvPrice);
    tvacceptedID= (TextView) findViewById(R.id.tvAcceptedID);
    btnResched = (Button) findViewById(R.id.btnResched);
    btnResched.setOnClickListener(this);

    Intent in2 = getIntent();
    e1 = in2.getStringExtra("e1");
    e2 = in2.getStringExtra("e2");
    e3 = in2.getStringExtra("e3");
    e4 = in2.getStringExtra("e4");
    e5 = in2.getStringExtra("e5");
    e6 = in2.getStringExtra("e6");
    e7 = in2.getStringExtra("e7");
    e8 = in2.getStringExtra("e8");
    e9 = in2.getStringExtra("e9");
    e10 = in2.getStringExtra("e10");
    e11 = in2.getStringExtra("e11");
    e12 = in2.getStringExtra("e12");

    tvCarModel.setText(e1);
    tvCarType.setText(e2);
    tvCapacity.setText(e3);
    tvPlateNumber.setText(e4);
    etResDate.setText(e5);
    etResTime.setText(e6);
    etResLocation.setText(e7);
    tvPoster.setText(e8);
    etDestination.setText(e10);
    tvPrice.setText(e11);
    tvacceptedID.setText(e12);

}

public void showDialogOnButtonClick(){
    etResDate = (EditText) findViewById(R.id.etResDate);
    etResTime = (EditText) findViewById(R.id.etResTime);

    etResDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DIALOG_ID);
        }
    });
    etResTime.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DIALOG_ID2);
        }
    });
}

@Override
protected Dialog onCreateDialog(int id) {
    if(id == DIALOG_ID){
        return new DatePickerDialog(this, dplistener, year_x,month_x,day_x);
    }

    else if (id == DIALOG_ID2){
        return new TimePickerDialog(this, tplistener, hour_x, minute_x,false);
    }

    return null;
}

private DatePickerDialog.OnDateSetListener dplistener = new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
        year_x = year;
        month_x = monthOfYear + 1;
        day_x = dayOfMonth;
        etResDate.setText(month_x + "/" +  day_x + "/" + year_x);
    }
};

protected TimePickerDialog.OnTimeSetListener tplistener = new TimePickerDialog.OnTimeSetListener() {
    @Override
    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        hour_x = hourOfDay;
        minute_x = minute;
        etResTime.setText(hour_x +" : " + minute_x );
    }
};

@Override
public void onClick(View v) {

    HashMap postData = new HashMap();

    postData.put("acceptedID",tvacceptedID.getText().toString());
    postData.put("etResDate",etResDate.getText().toString());
    postData.put("etResTime",etResTime.getText().toString());
    postData.put("etResLocation",etResLocation.getText().toString());
    postData.put("etResDestination",etDestination.getText().toString());


    PostResponseAsyncTask taskPost = new PostResponseAsyncTask(ReSchedClick.this, postData, new AsyncResponse() {
        @Override
        public void processFinish(String s) {
            if(s.contains("success")){
                Toast.makeText(ReSchedClick.this, "Rental rescheduled!", Toast.LENGTH_SHORT).show();
                Intent in3 = new Intent(ReSchedClick.this, RenterTabs.class);
                startActivity(in3);
                finish();
            }else{
                Toast.makeText(ReSchedClick.this, "Error", Toast.LENGTH_SHORT).show();
            }

        }

    });

    taskPost.execute("http://carkila.esy.es/reschedule.php");

}

0 个答案:

没有答案