繁体   English   中英

如何将意图从活动传递给扩展LinearLayout的类

[英]How do I pass an intent from an activity to a class extending LinearLayout

我必须将一个Intent值(字符串)传递给扩展LinearLayout的类。 我试过了

Intent in = new Intent(getApplicationContext(), Chat_Layout.class);
in.putExtra("Rid", RequestID); 

通过将值传递给linearlayout类,但由于在getIntent()中显示未定义的错误,因此无法检索该值。

ReqID = getIntent().getStringExtra("Rid");

您不能在ViewGroup调用getIntent()LinearLayout是该类的派生类)。 在扩展的LinearLayout ,您需要这样的内容:

public void setReqId(String rid) {
    this.rid = rid;
}

然后从您的活动中调用

extendedLinearLayout.setReqId(getIntent().getStringExtra("Rid");

当您引用扩展的LinearLayout时,可以从您的活动中执行此操作。 您可以在活动中获得对它的引用(假设您的类称为ExtendedLinearLayout

ExtendedLinearLayout extendedLinearLayout =
    (ExtendedLinearLayout)findViewById(R.id.extended_linear_layout);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM