How to return a value from a inner class?

前端 未结 5 535
抹茶落季
抹茶落季 2021-01-12 18:39

My code is here:

public static boolean showConfirmationDialog(Context context, String title, String dialogContent) {
        AlertDialog.Builder builder = ne         


        
5条回答
  •  隐瞒了意图╮
    2021-01-12 19:11

    The onClick paradigm doesn't let you return values, it lets you respond to "events" later, so you'll have to rethink your code paradigm a bit.

    For followers, in the event that the inner class is "blocking" (i.e. not this case), you can return values using AtomicReference, ex:

    AtomicReference returnValue = new AtomicReference<>();
    someMethod( new Runnable() { returnValue.set("my inner class value");} );
    return returnValue.get();
    

    though better would be (if possible) have someMethod modified so it can return your value out itself (and use something besides Runnable in this instance). GL!

提交回复
热议问题