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