2017-02-16 17 views
3

У меня странный вопрос. У меня есть простой alertDialog. Я передал ему аргументы, но я вижу его пустым, кроме значка.Бланк alertDialog

это метод:

public class ViewUtil { 

//// some code... 

public static void showMessagePopup(int titleResId, String message, Context context) { 
    new AlertDialog.Builder(context) 
      .setTitle(context.getResources().getString(titleResId)) 
      .setMessage(message) 
      .setIcon(R.mipmap.ic_launcher) 
      .show(); 
} 

И здесь я называю это

public class RedesignNewDriverPopup extends Dialog { 
/// some code... 

new PrepareRestApiTask<>(new PrepareRestApiTask.restApiCaller<String>() { 
       @Override 
       public Call<RestResponse<String>> onRestApiReadyBackgroundRun(String hashedToken, 
                       SmartbusClient client) { 
        return client.update_driver(driver.id, req, hashedToken); 
       } 

       @Override 
       public void onEverythingFinishedUIThreadRun(String theData) { 
        updateCallback.afterDriverUpdate(); 
        ViewUtil.showMessagePopup(R.string.new_driver, getContext().getResources().getString(R.string.driver_created), getContext()); 
        dismiss(); 
       } 

       @Override 
       public void onError(Response<RestResponse<String>> response) { 
        ViewUtil.showMessagePopup(R.string.new_driver, getContext().getResources().getString(R.string.login_error), getContext()); 
        dismiss(); 
       } 


      }).execute(); 

это моя тема:

`<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <!-- Customize your theme here. --> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">@color/colorAccent</item> 
    <item name="drawerArrowStyle">@style/DrawerArrowToggle</item> 
    <item name="android:actionBarStyle">@android:style/Widget.Holo.ActionBar</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:tabWidgetStyle">@style/CustomTabWidget</item> 
</style>` 

Как я уже сказал, я могу видеть значок, но а не название или сообщение.

Благодаря

+1

использование 'ActivityName.this' вместо' getContext' – rafsanahmad007

+0

где? когда я вызываю метод? но я не в действии Я в классе, который расширяет Dialog. своего рода всплывающее окно – Roish

+0

http://stackoverflow.com/a/33257083/7320259 –

ответ

1

попробовать это:

ViewUtil.showMessagePopup(activity_context.getResources().getString(R.string.new_driver), activity_context.getResources().getString(R.string.driver_created), activity_context); 

передать контекст активности в диалоговом классе и использовать его

Также в ваш:

public static void showMessagePopup(String titleResId, String message, Context context) { 
    new AlertDialog.Builder(context) 
      .setTitle(titleResId) 
      .setMessage(message) 
      .setIcon(R.mipmap.ic_launcher) 
      .show(); 
} 

Чтобы передать контекст:

//in activity 
MyDialogClass dialog=new MyDialogClass(this); 

Теперь в вашем диалоге использования класса:

Context activity_context; 
MyDialogClass(Context context){ 
this.activity_context=context; //now use activity_context to show alertDialog 
} 
+0

Спасибо человек. но я не занимаюсь. см. мое редактирование Я не думаю, что контекст является проблемой – Roish

+0

Пробовал ли вы пропустить статическую строку «вместо» из 'getResources.getString()' – rafsanahmad007

+0

см., что я сказал, что ваш контекст не прав .. – rafsanahmad007