0

情况:用户可以保存包含名称、描述和照片的项目。之后由 显示listview。当用户单击他们保存的项目之一时,显示他们在ViewWishlist.java班级中保存的项目的信息。在该页面中,有一个“编辑按钮”,如果用户单击该按钮,将执行编辑页面。

问题在于ViewWishlist class,name和description都是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));
            }
        }       
    }
4

2 回答 2

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

试试这个。

于 2013-05-23T11:40:30.990 回答
0

您实际上无法传递 textviews。尝试传递用于设置 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);

`

于 2013-05-23T11:52:27.847 回答