Android的对话活动 [英] Android Dialog Activity

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

问题描述

我需要帮助的以下内容:结果
当我触摸我的mainActivity,应该处理onTouch事件,并启动新的活动是一个对话的活动。我不能做到这一点。任何人都可以提出什么吗?

我添加安卓主题=@安卓风格/ Theme.Dialog。结果
如果我设计简单的对话活动,然后它工作正常,但如果我试图打开它的触摸事件,然后它不工作。

 公共布尔onTouch(视图V,MotionEvent事件){
    INT行动= event.getAction();
    如果(动作== MotionEvent.ACTION_DOWN){
        意图loginIntent =新意图(这一点,Login.class);
        startActivity(loginIntent);
        返回true;
    }
    返回true;
}


解决方案

您必须通过上下文的intent.and你刚才写的本。而你在侦听器,它通过监听器不是上下文你activity.so你需要在那里写YourActivity.this。
所以替换此行

 意图loginIntent =新意图(这一点,Login.class);

与此一

 意图loginIntent =新意图(YourActivity.this,Login.class);

和你done.hope有所帮助。

I need help on following:
When I touch on my mainActivity, it should handle onTouch event and start new activity which is a dialog activity. I am not able to do it. Can anyone suggest anything ?

I add android:theme="@android:style/Theme.Dialog".
If I design simple Dialog activity then it works fine but if I am trying to open it on touch event then it's not working.

public boolean onTouch(View v, MotionEvent event) {
    int action = event.getAction();
    if(action == MotionEvent.ACTION_DOWN) {         
        Intent loginIntent = new Intent(this, Login.class);
        startActivity(loginIntent);
        return true;
    }
    return true;
}

解决方案

you have to pass the context to your intent.and you have just wrote "this".and you are in Listener so it passes the Listener not the context of your activity.so you need to write YourActivity.this there. so replace this line

 Intent loginIntent = new Intent(this, Login.class);

with this one

 Intent loginIntent = new Intent(YourActivity.this, Login.class);

and you are done.hope this helps.

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

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