[英]How do I pass an intent from an activity to a class extending LinearLayout
I have to pass an Intent value (String) to my class extending LinearLayout. 我必须将一个Intent值(字符串)传递给扩展LinearLayout的类。 I had tried 我试过了
Intent in = new Intent(getApplicationContext(), Chat_Layout.class);
in.putExtra("Rid", RequestID);
by passing the value to the linearlayout class, but can't retrieve the value since it shows undefined error in getIntent(). 通过将值传递给linearlayout类,但由于在getIntent()中显示未定义的错误,因此无法检索该值。
ReqID = getIntent().getStringExtra("Rid");
You cannot call getIntent()
in a ViewGroup
( LinearLayout
is a derived class of that). 您不能在ViewGroup
调用getIntent()
( LinearLayout
是该类的派生类)。 In your extended LinearLayout
, you need something like this: 在扩展的LinearLayout
,您需要这样的内容:
public void setReqId(String rid) {
this.rid = rid;
}
And from your activity call it with 然后从您的活动中调用
extendedLinearLayout.setReqId(getIntent().getStringExtra("Rid");
You can do this from your activity when you have a reference to your extended LinearLayout
. 当您引用扩展的LinearLayout
时,可以从您的活动中执行此操作。 You can get a reference to it like so in your activity (assuming your class is called ExtendedLinearLayout
您可以在活动中获得对它的引用(假设您的类称为ExtendedLinearLayout
ExtendedLinearLayout extendedLinearLayout =
(ExtendedLinearLayout)findViewById(R.id.extended_linear_layout);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.