Reputation: 313
I have an activity that is launched from another activity through an intent. The intent carries an extra "id" information. Now, the launched activity has a custom view (actually, a extension of LinearLayout class). I want to access the "id" information in the custom view. Can the activity pass that value to its contained view? Or can the view get a handle to the activity?
Upvotes: 2
Views: 3460
Reputation: 35946
YES,
First you have pass id with the intent like
Intent i=new Intent(getApplicationContext(), sample.class);
i.putExtra("id", id);
startActivity();
it pass the value to sample class
here
String i=getIntent().getExtras().getSerializable("id").toString();
& you can use this id in your custom view
Upvotes: 4
Reputation: 11620
Yes, your custom View class can get a reference to the Activity it is contained in. Every View has a getContext() method which returns the Context the View is running in (i.e. your Activity).
Upvotes: 2
Reputation: 2087
make a method in your view that takes the id as a parameter, and then call that method from your activity.
Upvotes: 2