状況: ユーザーは、名前、説明、および写真を含むアイテムを保存できます。その後、 によって表示されlistview
ます。ViewWishlist.java
ユーザーが保存したアイテムの 1 つをクリックすると、クラスに保存したアイテムの情報が表示されます。そのページには「編集ボタン」があり、ユーザーがボタンをクリックすると、編集ページが実装されます。
問題はViewWishlist class
、名前と説明が であるということTextview
です。に渡す必要がありEditView
ます。
私は試した
current_item.putString("name", name);
current_item.putString("note, note);
しかし、それはエラーになります..TextViewタイプをeditTextに渡すためにどのメソッドを使用する必要がありますか. どうすればこれを行うことができますか?..よろしくお願いします! 私のコードはここにあります
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));
}
}
}