开发者

Passing extra Intent information from Activity to View

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开发者_JAVA技巧 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


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).


make a method in your view that takes the id as a parameter, and then call that method from your activity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜