简体   繁体   English

来自扩展MainActivity的类的开放活动

[英]Open activity from class that extends MainActivity

I am dynamically adding rows to a table in my MainActivity from a class that extends MainActivity. 我正在通过扩展MainActivity的类将行动态添加到MainActivity中的表中。 In this class that I call FeedRow I assign an onClick listener to a button that was in the layout I used to inflate the row with. 在我称为FeedRow的此类中,我将一个onClick侦听器分配给按钮上的按钮,该按钮用于填充行。 When I click the button to load an activity the cat says that the intent is null. 当我单击按钮加载活动时,猫说意图是空的。 I hope you understand my question. 我希望你能理解我的问题。 Thank you. 谢谢。

04-01 23:47:40.282: E/AndroidRuntime(1122):     at android.content.ComponentName.<init>(ComponentName.java:77)
04-01 23:47:40.282: E/AndroidRuntime(1122):     at android.content.Intent.<init>(Intent.java:3813)

Class: 类:

public class FeedRow extends MainActivity implements OnClickListener {

String status = "";
Context context
View v;

 FeedRow(Context context, TableLayout table, String status){
// A lot of code to create the row button shown only...

 Button button = (Button)v.findViewById(R.id.commentButton);
 button.setOnClickListener(this);

 } 


@Override
public void onClick(View v) {
// Intent will be null when I try to run
   Intent intent = new Intent(context, CommentActivity.class);
   startActivity(intent);
}

I'm not exactly sure what you're trying to do, but your Activity should not have a constructor. 我不确定您要做什么,但是您的Activity应该没有构造函数。 Secondly, for your context , you can simple use this , as Activity, somewhere down the line extends Context . 其次,对于您的context ,您可以简单地使用this作为Activity,将其扩展到Context

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

相关问题 调用从MainActivity类扩展Activity的Fragment扩展的类Fragment - Calling a Class Fragment which extends Fragment from a MainActivity Class which extends Activity 从扩展MainActivity的类中调用public void - Call public void from class that extends MainActivity 从扩展Service的类更新MainActivity的textview - Update textview of MainActivity from class that extends Service 使用另一个活动 java class 打开 MainActivity - open MainActivity using another activity java class 将值从MainActivity传递到扩展Fragment的Java_Class失败 - Passing values from MainActivity to a Java_Class that extends Fragment fails 是否有从其他活动 class 访问 MainActivity 的解决方案? - Is there a solution that access MainActivity from other Activity class? 如何从MainActivity类文件扩展活动? - How to extend an activity from the MainActivity class file? 将数据从“扩展活动”的类传递到“扩展片段”的类 - Passing data from a class that 'extends activity' to a class that 'extends fragment' 从另一个将活动扩展到扩展视图的类的类访问变量 - Acces to variable from another a class that extends activity to a class that extends view 从扩展 Fragment 的类启动 AppCompatActivity Activity - Starting an AppCompatActivity Activity from a class that extends Fragment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM