简体   繁体   English

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

[英]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.

相关问题 将意图从活动传递给扩展Application的类 - Pass an intent from activity to a class extending Application 如何通过活动类将参数传递给android中的类扩展视图 - How to pass parameters to a class extending view in android from activity class 如何从 class 扩展 LinearLayout 访问相机? - how to access the camera from class extending LinearLayout? 如何在 Intent intent = new Intent(mContext, c_Report_Activity.class); 处传递 putExtra; - How can I pass putExtra at Intent intent = new Intent(mContext, c_Report_Activity.class); 如何在另一个类中使用“ MainActivity类”中的意图传递数据,而不扩展任何类 - How to use intent pass data from 'MainActivity class' in another class, not extending any class 如何使用意图将ArrayList传递给另一个Activity? - How do I pass ArrayList to another Activity using intent? 如何将活动意图传递给另一个班级? - How to pass an activity intent to another class? 如何从 Intent 遍历自定义对象的 ArrayList 并将它们添加到 LinearLayout? - How do I iterate through an ArrayList of custom objects from Intent and add them into LinearLayout? 如何使用arrayAdapter中的intent进入第三个活动? - How do I use intent from arrayAdapter to go into a third activity? 如何将数组从java android活动类传递给普通的java类? - How do I pass arrays from a java android activity class to a normal java class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM