Android startActivity 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24808094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
startActivity not working
提问by 999
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
//Toast.makeText(getApplicationContext(), "Position of selected item is: "+ position, Toast.LENGTH_LONG).show();
if ("Abiding in Christ".equals(categories[position]))
{startActivity(AbidingInChrist.class);}
else if ("Abundant Living".equals(categories[position]))
{startActivity(AbundantLiving.class);}
else if ("Access to God".equals(categories[position]))
{startActivity(AccessToGod.class);}
else if ("Adoration of God".equals(categories[position]))
{startActivity(AdorationOfGod.class);}
else if ("Amazing Grace".equals(categories[position]))
{startActivity(AmazingGrace.class);}
all of the startActivity s are underlined in red and want me to change to something or create a method same name. I did add all the activities to the manifest, but some of them didn't work:
所有 startActivity 都用红色下划线标出,并希望我更改为某些内容或创建一个相同名称的方法。我确实将所有活动添加到清单中,但其中一些活动不起作用:
<activity android:name=".AbidingInChrist"</activity>
<activity android:name=".AbundantLiving</activity>
<activity android:name=".AccessToGod</activity>
<activity android:name=".AdorationOfGod</activity>
<activity android:name=".AmazingGrace</activity>
<activity android:name=".AnsweredPrayer</activity>
<activity android:name=".Atonement</activity>
<activity android:name=".Attitudes</activity>
<activity android:name=".Belief</activity>
<activity android:name=".Blessing</activity>
<activity android:name=".BloodOfJesus</activity>
<activity android:name=".Boldness</activity>
<activity android:name=".Brokenness</activity>
<activity android:name=".Calling</activity>
<activity android:name=".Comfort</activity>
<activity android:name=".Commitment</activity>
It's hard to tell here, but every other one was in red saying that it was missing the android namespace prefix.
在这里很难说,但其他每个人都是红色的,说它缺少 android 命名空间前缀。
Appreciate ya'll!
欣赏你!
回答by PedroHawk
In your code try to use an intent to start activity:
在您的代码中尝试使用意图开始活动:
Intent i = new Intent(ACTUALACTIVITY.this, OTHERACTIVITY.class);
startActivity(i);
and in your manifest put your activity full address (package.activity) like below:
并在您的清单中输入您的活动完整地址(package.activity),如下所示:
<application>
(...)
<activity
android:name="packagename.YOURACTIVITY">
</activity>
</application>
回答by Lanitka
Try to create Intent and start Activity passing this intent like
尝试创建 Intent 并启动 Activity 传递此 Intent,例如
// Create intent to start new Activity
Intent intent = new Intent(context, YourActivity.class);
startActivity(intent);
回答by Carlos J
The startActivity
method takes an Intent
as parameter. Yo are trying to pass a class and that's why you get the "red underline"
该startActivity
方法采用一个Intent
作为参数。你正试图通过一门课,这就是为什么你得到“红色下划线”
try this:
尝试这个:
if ("Abiding in Christ".equals(categories[position]))
{startActivity(new Intent(this, AbidingInChrist.class));}
else if ("Abundant Living".equals(categories[position]))
{startActivity(new Intent(this, AbundantLiving.class));}
else if ("Access to God".equals(categories[position]))
{startActivity(new Intent(this, AccessToGod.class));}
else if ("Adoration of God".equals(categories[position]))
{startActivity(new Intent(this, AdorationOfGod.class));}
else if ("Amazing Grace".equals(categories[position]))
{startActivity(new Intent(this, AmazingGrace.class));}
Also in you manifest don't forget to close the quotes when you declare an activity
同样在您的清单中,请不要忘记在声明活动时关闭引号
<activity android:name=".AbidingInChrist"></activity>
<activity android:name=".AbundantLiving"></activity>
<activity android:name=".AccessToGod"></activity>
etc
等等