情况:
用户可以保存包含姓名,描述和照片的项目。
之后由listview
显示。
当用户单击其中一个已保存的项目时,会显示他们在ViewWishlist.java
课程中保存的项目的信息。
在该页面中,有一个“编辑按钮”,如果用户单击该按钮,
编辑页面将被实施。
问题在于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));
}
}
}
答案 0 :(得分:0)
Intent intent=new Intent(ViewWishlist.this, AddEditWishlists.class);
Bundle current_item = new Bundle();
current_item.putString("name", name);
current_item.putString("note", note);
current_item.putByteArray("blob", image);
/** You need to add this line to pass Bundle data to An Other Activity */
intent.putExtras(current_item);
startActivity(intent);
试试这个。
答案 1 :(得分:0)
你实际上无法传递textviews.Try传递用于设置textviews的字符串。 像,
String abc="hello";
name.settext(abc); //here name is your textview
现在通过意图传递此字符串abc。
`
Intent intent=new Intent(ViewWishlist.this, AddEditWishlists.class);
Bundle b = new Bundle();
b.putString("name", abc);
intent.putExtras(b);
startActivity(intent);
`