ANDROID:将文字发送到下一页

时间:2016-08-30 05:28:49

标签: android

大家好我不知道如何使用按钮将textview的文本发送到下一页的editText,使用intent转到下一页。在此先感谢您的帮助。这是我的代码。 :)

ownerDetails.class

public class OwnerDetail extends AppCompatActivity {
TextView tvCarModel, tvCarType, tvCapacity, tvFuelType, tvPlateNumber, tvPoster,tvCarPrice;
ImageView ivImage;
Button btnEdit, btnDelete;
private FunDapter<Cars> adapter;



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

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final Cars Cars = (Cars)getIntent().getSerializableExtra("cars");

    ImageLoader.getInstance().init(UILConfig.config(OwnerDetail.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);
    tvCarPrice = (TextView) findViewById(R.id.tvCarPrice);
    ivImage = (ImageView)findViewById(R.id.ivImage);
    btnEdit = (Button) findViewById(R.id.btnEdit);
    btnEdit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent in = new Intent(OwnerDetail.this, UpdateClick.class);
            startActivity(in);
        }
    });


    try {
        if (Cars != null) {
            tvCarModel.setText("Car Model: "+Cars.Car_Model);
            tvCarType.setText("Car Type: "+ Cars.Car_Type);
            tvCapacity.setText("Capacity: "+Cars.Capacity);
            tvFuelType.setText("Fuel Type: "+Cars.FuelType);
            tvPlateNumber.setText("Plate Number: "+Cars.PlateNumber);
            tvPoster.setText("Posted by: " + Cars.owner);
            tvCarPrice.setText("Price: " + Cars.carPrice);

            ImageLoader.getInstance().displayImage(Cars.Image, ivImage);

        }
    }catch (Exception e){
        System.out.println("Error in details " + e.toString());
    }

}

}

UpdateClick.class

public class UpdateClick extends AppCompatActivity {

EditText etCarModel;
EditText etCarType;
EditText etCapacity;
EditText etPlateNumber;
ImageView ivImg;
Spinner spFuelType;
Button btnSelectPhoto,btnUpdate;
GalleryPhoto galleryPhoto;
Bitmap bitmap;
final String TAG = this.getClass().getName();
final int GALLERY_REQUEST = 1231;
String selectedPhoto;


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == GALLERY_REQUEST) {
            Uri uri = data.getData();
            galleryPhoto.setPhotoUri(uri);
            String photoPath = galleryPhoto.getPath();
            selectedPhoto = photoPath;
            try {
                bitmap = com.kosalgeek.android.photoutil.ImageLoader.init().from(photoPath).requestSize(512, 512).getBitmap();
                ivImg.setImageBitmap(bitmap);
            } catch (FileNotFoundException e) {
                Toast.makeText(getApplicationContext(), "Something went wrong while opening gallery", Toast.LENGTH_SHORT).show();
            }
        }
    }
}

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


    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    galleryPhoto = new GalleryPhoto(getApplicationContext());
    spFuelType = (Spinner) findViewById(R.id.spFuelType);
    adapter = ArrayAdapter.createFromResource(this, R.array.fuel_types,android.R.layout.simple_dropdown_item_1line);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spFuelType.setAdapter(adapter);
    spFuelType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

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

    etCarModel = (EditText) findViewById(R.id.etCarModel);
    etCarType = (EditText) findViewById(R.id.etCarType);
    etCapacity = (EditText) findViewById(R.id.etCapacity);
    etPlateNumber = (EditText) findViewById(R.id.etPlateNumber);
    ivImg = (ImageView) findViewById(R.id.ivImg);
    btnSelectPhoto = (Button) findViewById(R.id.btnSelectPhoto);


    btnSelectPhoto.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivityForResult(galleryPhoto.openGalleryIntent(), GALLERY_REQUEST);
        }
    });



}

2 个答案:

答案 0 :(得分:0)

您可以使用意图发送文本到其他页面,如下所示:

    String sometext = textview.getText().toString();
    Intent i = new Intent(CurrentActivity.this, nextActivity.class);
    i.putExtra("myText", sometext);
    startActivity(i);

并且在nextActivity中使用可以这样:

onCreate()

中的

Intent intent = getIntent();
String getNewText = intent.getStringExtra("myText");

现在你可以将你的字符串设置为任何edittext ..我希望你能得到它。

答案 1 :(得分:0)

使用intent.putextra()

Button button = (Button)findViewById(R.id.button)

button.setOnClickListener(new View.OnClickListener() { 
    @Override public void onClick(View v) {

    Intent intent = new Intent(this,NextActivity.class);
   // send text to next activity 

    intent.putExtra("text",textView.getText().toString())
    startActivity(intent);
}
});

在下一个活动的onCreate()方法中对此进行编码

Bundle bundle=getIntent().getExtras();

editText=(EditText)findViewById(R.id.editText);           
editText.setText(bundle.getString("text"));