tags:

views:

48

answers:

1

Here is my code:

private Button.OnClickListener gotologinpage3 = new Button.OnClickListener() {
    public void onClick(View v) {
        try {
            Intent ii = new Intent(v.getContext(), login_profile.class);
            startActivityForResult(ii,0);
        } 
        catch (Exception e) {
            e.printStackTrace();
            // TODO: handle exception
        }
    }
};

Can I pass button id to function makenewProfile from class login_profile?

+3  A: 

Yes, you can add extras:

Intent ii = new Intent(v.getContext(), login_profile.class);
ii.putExtra("id", myId);

startActivityForResult(ii, 0);

And pick them up like so:

Bundle extras = getIntent().getExtras();
int id = extras.getInt("id");
David Hedlund
Thank you very much sir.
RBADS
one more question sir, i can call function and pass same value in anther class using same above code?i mean to say that i hava a functin name "makeNewProfile" in class login_profile and i want to call this function as well as pass same value.
RBADS
i'd say the easiest way to do that, would be to add another extra, such as `ii.putExtra("makeNewProfile", true);` and fetch it in `login_profile`: `if(extras.getBoolean("makeNewProfile")) { makeNewProfile(); }`
David Hedlund
Hey Bibek, just as a heads-up, you should mark answers as accepted (the little checkmark on the left) if they answer you question. That helps people build reputation and rewards them for spending time answering your questions.
fiXedd