1

Here is the class i am passing to

public class AxxessCCPAccountDetails extends Activity {

public AxxessCCPAccountDetails(String username) {

}
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.accountdetails);
}

}

Here is the code that i am passing from

lv.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {
        // When clicked, show a toast with the TextView text
        Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
            Toast.LENGTH_SHORT).show();

        Intent myIntent = new Intent(view.getContext(), AxxessCCPAccountList.class);
        startActivityForResult(myIntent, 0);
      }
    });

I need to pass a username to a class. How can i pass the param to the class then activate the activity(class) which is linked to a view.

Thanks

3 Answers 3

5

Using Intent. You should not create your own constructor for the Activity class.

Here is a short example:

Intent myIntent = new Intent(view.getContext(), AxxessCCPAccountList.class);
myIntent.putExtra("username", userName);
myIntent.putExtra("pass", pass);

And then, in your AxxessCCPAccountList.onCreate method:

String userName = this.getIntent().getStringExtra("username");
String pass = this.getIntent.getStringExtra("pass");
Sign up to request clarification or add additional context in comments.

2 Comments

String userName = this.getIntent().getExtra("username"); When i try do this it says that getextra does not exist
I forgot that when gettings extras, you do specify the type. So: String userName = this.getIntent().getStringExtra("username");. Ill edit the code now
1

Add the data to the intent (intent.putExtra() or something), and get it on the other side from the intent in onCreate (intent.getExtra() ) by using the same key.

Comments

0

This is the solution

getIntent().getExtras().getString("username");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.