安卓:为响应的用户界面的最佳实践 [英] Android: Best practice for responsive user interfaces

查看:132
本文介绍了安卓:为响应的用户界面的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新到Android和Java。我正在用C ++哪里哪里与信息调度的事件之前。现在,我想创造Android平台相同的用户体验,我想AP preciate任何您对什么是将事件绑定到用户控件的最佳方法的建议和意见。

I am quite new to Android and Java. Before I was working with C++ where the events where dispatched with messages. Now I would like to create the same user experience for Android platform and I would appreciate any of your suggestions or comments on what is the best way to bind events to user controls.

下面是C ++的一个例子:

Here is an example from C++:

ON_MESSAGE(WM_RECORD_START, &CMainFrame::OnRecordStart)//Method OnRecordStarts() executes on WM_RECORD_START_MESSAGE

...

LRESULT CMainFrame::OnRecordStart(WPARAM wParam, LPARAM lParam)
{

        m_pNetworkCtrl->SetGeoLocationInfo();
        ...
}

...

void CMainFrame::RecordStart()
{
    PostMessage(WM_RECORD_START);
}

在上面的方法的情况下 RecordStart()绑定到按钮(被执行时按钮是pressed)和职位的消息 WM_RECORD_START 。当消息 WM_RECORD_START 收到,该方法 OnRecordStart()被执行。

In the case above the method RecordStart() is bound to a Button (it is executed when a Button is pressed) and posts the message WM_RECORD_START. When the message WM_RECORD_START is received, the method OnRecordStart() is executed.

如前所述,我想创建一个响应的用户界面,我不知道这是否会不够好,如果该方法 OnRecordStart()是直接从<$称为C $ C> RecordStart():

As mentioned before I would like to create a responsive user interface and am not sure if it would be good enough if the method OnRecordStart() is called directly from RecordStart():

void RecordStart()
{
    OnRecordStart();
}

我真的AP preciate你的任何建议。

I would really appreciate any of your suggestions.

推荐答案

您可以通过使用的处理器张贴可运行到消息队列。

You can emulator the MFC style behavior in Android by using a Handler to post a Runnable into the message queue.

下面是一个简单的例子

class MyClass
{
    Handler m_myHandler;
    Runnable m_myRunnable;

    MyClass()
    {
        m_myHandler = new Handler();
        m_myRunnable = new RUnnable()
        {
            public void run()
            {
                // do your stuff here
            }
        };
    }

    public void onclickListener(...)
    {
        // push the runnable into the message queue
        m_myHandler.post(m_myRUnnable);
    }
}

这篇关于安卓:为响应的用户界面的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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