开发者

CustomDialog vs. Activity with theme.dialog

I need a dialog with 2 text views and about 8 buttons + ok and cancel button. Pressing one of 8 buttons should change text views. Ok button should return last pressed button and cancel should return a special value.

I think that for this is better a special activity than a custom dialog but I have a problem with returning a last switched button.

handler = new Hand开发者_如何学编程ler() {
        @Override 
        public void handleMessage(Message msg) 
        { 
            Intent intent = new Intent(context, Spellbook.class);
            context.startActivity(intent);
        }
    };

I'm not starting the activity from the main thread so I have to use a handler but I don't know how can I start the activity with response there. Any idea how to solve it?


Are you just having an issue getting the value back from the started activity?

If so you just need to handle the onActivityResult() method on the Activity that is used as the context for the new Intent and make sure in the called Activity that you use setResult() and finish()..

In the called Activity..

setResult(RESULT_OK, /* Some Intent with Data should go here */ null);
finish();

In the calling Activity..

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    /* Handle result and extract data from Intent */
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜