J. Shmoe J. Shmoe - 3 months ago 22
Android Question

ANDROID: Send text to next page

Hi guys I dont know how to send the texts of my textview to the editText of my next page using a button to go to the next page using intent. Thanks in advance for the help. Here are my codes. :)

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);
}
});



}

Answer

you can use intent send text to other page like this:

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

and in nextActivity use can get like this:

in onCreate()

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

now you can set your string to any edittext.. i hope you got it.

Comments