Reputation: 1043
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
Upvotes: 1
Views: 238
Reputation: 9115
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");
Upvotes: 5
Reputation: 39386
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.
Upvotes: 1