在Android中嵌套的内部活动类 [英] Nested inner Activity class in android

查看:189
本文介绍了在Android中嵌套的内部活动类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时宣布扩大活动在另一个活动类可能的一类?如果是,我怎么会注册这个类在清单?此外,就是一些可以合理地完成还是一个坏主意?

Is declaring a class that extends Activity inside another Activity class possible? If it is, how would I register that class in the manifest? Also, is that something that can be reasonably done or is it a bad idea?

我在想是这样

class ListClass extends ListActivity{

    ...
    ArrayList items;

    class ItemClass extends Activity{

        ...
        Item item;

        @Override
        onCreate(){
            Integer pos = getIntent().getExtras().getInt("pos");
            item = items.get(pos);
        }
    }

    @Override
    onItemClick(int position){

        startActivity(new Intent(this, ItemClass.class).putExtra("pos", position));

    }
}

请注意语法是不是100%正确明显,主要是伪code。

Note the syntax isn't 100% correct obviously, mostly pseudocode.

推荐答案

没有,那是不可能的。毕竟,Android操作系统将需要实例化的活动,如果它开始在任何时候(比如说,如果你通过一个意图启动),这是不可能的实例化一个 itemClass时没有父 ListClass

No, that's not possible. After all, the Android operating system will need to instantiate the Activity if it is started at any point (say, if you start it through an intent), and it's impossible to instantiate an ItemClass without a parent ListClass.

记住,每个活动是完全独立的,可以在任何时候通过一个意图开始。

Remember that each Activity is completely independent and can be started at any point through an intent.

这篇关于在Android中嵌套的内部活动类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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