0

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));
            }
        }       
    }
mmBs
  • 8,421
  • 6
  • 38
  • 46
hurj
  • 35
  • 1
  • 3
  • 10

2 Answers2

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

Try this.

Amit Gupta
  • 8,914
  • 1
  • 25
  • 33
  • I tried but same error. Error says "The method putString(String, String) in the type Bundle is not applicable for the arguments (String, TextView) – hurj May 23 '13 at 11:47
  • any more suggestions?...putString should be changed something else i guess..but i don't know what it would be – hurj May 23 '13 at 11:52
  • You need to use like name.getText().toString(). i.e current_item.putString("name", name.getText().toString()); – Amit Gupta May 23 '13 at 11:55
0

You cant actually pass textviews.Try passing the strings which are used to set your textviews. Like,

 String abc="hello";
name.settext(abc); //here name is your textview

Now pass this String abc through intents.

`

Intent intent=new Intent(ViewWishlist.this, AddEditWishlists.class);                
                Bundle b = new Bundle();
                b.putString("name", abc);

                intent.putExtras(b);
                startActivity(intent);

`

Basim Sherif
  • 5,384
  • 7
  • 48
  • 90
  • Btw, why TextView type cannot be passed? – hurj May 23 '13 at 12:06
  • Because textview is a View.You cant pass views through intents.And textview.gettext() method in other answer is not the right way to do it.If you already have the string then why you need to get the same from textview again? – Basim Sherif May 23 '13 at 12:10
  • there is no string in ViewWishlist.java . that's why I need to get the string type from text view – hurj May 23 '13 at 12:17
  • String name=Yourclassname.stringname; And you should declare your string in that class as public – Basim Sherif May 23 '13 at 12:22
  • failed...then do you know how to implement a method in another class ? – hurj May 23 '13 at 12:55
  • I tried to use the "string name" which is in the method "bindView" in the CustomWishlistAdapter.java. I define variable like this. public String one = CustomWishlistsAdapter.bindView.name; but it was failed – hurj May 23 '13 at 13:29
  • it says, the string name i want to use should be declared with static type...but i don't want to change it to static – hurj May 23 '13 at 13:45
  • why you dont want to change it to static? its the correct method.In that way you should do it.You cant always fetch strings from textviews.hmm anyway as you wish. – Basim Sherif May 23 '13 at 16:34