Android 函数接受字符串和字符串资源

标签 android

我的应用程序中有以下接口(interface)/合约

interface View {

    void showError(@StringRes int message);

    void showError(String message);

    void showLoading();

    void dismissLoading();

    void accountCreated();
}

我有 2 个 showError 函数,一个接受任何字符串作为参数,另一个接受 Android 字符串资源 (int)。

是否有一种方法可以仅使用一个更通用的 showError 来接受这两个参数?

最佳答案

你可以这样做

void showError(Object message){
   if(message instanceof String){

   }else if(message instanceof Integer){

   }
}

关于Android 函数接受字符串和字符串资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39825939/

相关文章:

android - IBM 蓝调 : make POST request from Android and how to handle it in NodeJS

java - 底部导航 fragment 应用程序不断崩溃

android - Xamarin Forms 自定义字体不适用于 UWP(适用于 Android)

android - 错误 : Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo'

android - WiFiDirectActivity 是什么/在哪里

android - 以编程方式将 View 添加到 Fragment onCreateView 方法

android - 如何通过应用程序将音乐排队到默认的 android 音乐播放器?

android - 使用 exoplayer 从 azure 媒体服务获取 Widevine 离线许可证

php - 如何使用php搜索该字符串是否作为android中mysql数据库中的值存在?

android - Gradle任务开始时不调用