Situation:
Users can save an item containing name, description and photo.
After that it's showed by listview
.
When users click one of items they saved, shows the information of the item they saved on the ViewWishlist.java
class.
In that page, there is a "edit button", and if users click the button,
edit page would be implemented.
Problem is that in the ViewWishlist class
, name and description are Textview
.
I need to pass it to EditView
.
I tried
current_item.putString("name", name);
current_item.putString("note, note);
But it makes error..what method do i need to use to pass the TextView type to editText. How can I do this?..Thanks in advance! my code is here
ViewWishlist.java
public class ViewWishlist extends Activity {
private TextView name;
private TextView note;
private ImageButton photo;
private byte[] image;
private ImageButton editBtn;
LayoutInflater inflator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_wishlist);
setUpViews();
editBtn = (ImageButton) findViewById(R.id.edit);
editBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(ViewWishlist.this, AddEditWishlists.class);
//How can I fix this part?////////////////////
Bundle current_item = new Bundle();
current_item.putString("name", name);
current_item.putString("note", note);
current_item.putByteArray("blob", image);
startActivity(intent);
}
});
}
public void setUpViews() {
name = (TextView) findViewById(R.id.inputname);
note = (TextView) findViewById(R.id.inputnote);
photo = (ImageButton) findViewById(R.id.inputphoto);
// When a photo is clicked, this event would be implemented
photo.setOnClickListener(new ImageButton.OnClickListener(){
// Display bigger images
//send byte array data with bundle to "view_photo.java"
public void onClick(View v){
Intent intent = new Intent(ViewWishlist.this, view_photo.class);
Bundle current_photo = new Bundle();
current_photo.putByteArray("blob", image);
intent.putExtras(current_photo);
startActivity(intent);
}
});
Bundle extras = getIntent().getExtras();
// Get the data from the sent Bundle from CustomWishlistsAdapter.java
if (extras != null) {
name.setText(extras.getString("name"));
note.setText(extras.getString("note"));
image = extras.getByteArray("blob");
if (image != null) {
if (image.length > 3) {
photo.setImageBitmap(BitmapFactory.decodeByteArray(image,0,image.length));
}
}
}
}
}
AddEditWishlists.java
public class AddEditWishlists extends Activity {
//Define Variables
private EditText inputname;
private EditText inputnote;
private Button upload;
private Bitmap yourSelectedImage;
private ImageView inputphoto;
private Button save;
private int id;
private byte[] blob=null;
byte[] image=null;
/**
* Show the layout when this class is started
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_wishlist);
setUpViews();
//top.xml
ImageButton back_btn = (ImageButton) findViewById(R.id.back_to_main_btn);
back_btn.setOnClickListener(new ImageButton.OnClickListener() {
public void onClick(View v){
Intent intent = new Intent(AddEditWishlists.this, main.class);
startActivity(intent);
}
});
}
/**
* Implemented when users click the one of the item on the wishlist
*/
private void setUpViews() {
inputname = (EditText) findViewById(R.id.inputname);
inputnote = (EditText) findViewById(R.id.inputnote);
inputphoto = (ImageView) findViewById(R.id.inputphoto);
Bundle extras = getIntent().getExtras();
if (extras != null) {
id=extras.getInt("id");
inputname.setText(extras.getString("name"));
inputnote.setText(extras.getString("note"));
image = extras.getByteArray("blob");
if (image != null) {
if (image.length > 3) {
inputphoto.setImageBitmap(BitmapFactory.decodeByteArray(image,0,image.length));
}
}
}