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?
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
在视图中创建一个以id作为参数的方法,然后从您的activity中调用该方法。
是的,您的自定义View类可以获得对它所包含的Activity的引用。每个View都有一个getContext()方法,它返回View正在运行的Context(即您的Activity)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.