通过启动一个setClassName新意图与机器人同packege [英] Start a new Intent by setClassName with same packege in android

查看:165
本文介绍了通过启动一个setClassName新意图与机器人同packege的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开始一个活动课,我知道如何开始一个活动,但问题是,我的类名是动态的。我的意思是我们有5个活动命名
1.活动
2.通知
3.聊天
4.消息
5.设置

I have to start a activity class , i know how to start an activity but the problem is that my class name is dynamic. I mean we have 5 activity named 1. Events 2. Notification 3. Chat 4. Message 5. Settings

我们还可以选择显示在此TabWidget上面的名字,但他的名字的顺序是从服务器的到来。因此,在第一个索引服务器的某个时候回归活动,有时通知是在第一个索引。为了可以动态改变,它可能返回两个或三个,并根据我们必须拿出TabWidget。

we also have to show this above name in TabWidget but the order of his name is coming from server . Hence sometime server return Events at first index, sometimes notification is at first index. order can be changed dynamically and it may return two or three of them and according to that we have to show the TabWidget.

它意味着如果服务器返回数组两个字符串,然后我们只有两个选项卡,如果它返回三个那么我们有三个选项卡。

its means if the server returning array with two string then we have only two tab if it return three then we have three tab.

目前我使用这种方法来动态地添加标签

currently I am using this method to add tab dynamically

private void setTabDynimacaaly() {
String NameOfClass;
for (int i = 0; i < menuListArray.size(); i++) {
    NameOfClass = menuListArray.get(i).get(4).toString().trim();
    intent = new Intent().setClassName("com.mcm.menuandnotification",
            "com.mcm.menuandnotification" + NameOfClass);

    spec = tabHost.newTabSpec(NameOfClass).setIndicator("")
            .setContent(intent);

    // Add intent to tab
    tabHost.addTab(spec);
  }
}

我menuListArray有datalike这种

my menuListArray has datalike this

06-02 07:18:06.732: E/MY APP MENU DATA(19739): [[38, 206, 5, MyChurchMateApp, Events, 1, \Images\MyChurchMateApp\ThemeImages\], [38, 206, 4, MyChurchMateApp, Notifications, 5, \Images\MyChurchMateApp\ThemeImages\], [38, 206, 7, MyChurchMateApp, Settings, 100, \Images\MyChurchMateApp\ThemeImages\]]

和清单中我已经宣布所有活动

and in manifest i have declared all the activity

<activity
  android:name=".menuandnotification.TabBar"
  android:screenOrientation="portrait" >
  </activity>
  <activity
  android:name=".menuandnotification.Events"
 android:screenOrientation="portrait" >
</activity>
   <activity
    android:name=".menuandnotification.Notifications"
   android:screenOrientation="portrait" >
  </activity>
  <activity
     android:name=".menuandnotification.Message"
    android:screenOrientation="portrait" >
</activity>
<activity
  android:name=".menuandnotification.Chat"
 android:screenOrientation="portrait" >
</activity>

<activity
  android:name=".menuandnotification.Settings"
 android:screenOrientation="portrait" >
</activity>

但它是越来越坠毁,
   我的错误是logcat中

but it is getting crashed and my error logcat is

06-02 07:18:07.662: E/AndroidRuntime(19739): java.lang.RuntimeException: Unable to  
start activity ComponentInfo{com.mcm/com.mcm.menuandnotification.TabBar}: 
android.content.ActivityNotFoundException: Unable to find explicit activity class  
{com.mcm.menuandnotification/com.mcm.menuandnotificationEvents}; have you declared 
this activity in your AndroidManifest.xml?

请帮助我如何达致这?

推荐答案

我认为你只是缺少一个。字符您指定字符串中在下面一行的意图:

I think you are just missing a . character in your specified string for the Intent in the following line:

intent = new Intent().setClassName("com.mcm.menuandnotification",
        "com.mcm.menuandnotification" + NameOfClass);

将其更改为:

intent = new Intent().setClassName("com.mcm.menuandnotification",
        "com.mcm.menuandnotification." + NameOfClass);

编辑:

如果没有工作,怎么样尝试以下操作:

If that didn't work, how about trying the following:

Class<?> clazz = Class.forName("com.mcm.menuandnotification." + NameOfClass); 
intent.setClass(this, clazz);

这篇关于通过启动一个setClassName新意图与机器人同packege的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆