alertdialog

Toast.maketext第一个参数context的问题

我怕爱的太早我们不能终老 提交于 2019-12-04 13:48:48
在Android工程中经常用到 Toast来显示提示,在maketext的第一个参数是要求传递一个context 那么问题来了 有时候是使用getApplicationContext(); 有时候是Activity.this 而有时候又直接是 this 在android中常常会遇到与context有关的内容,大多都是作为参数在传递,但是它的作用究竟是什么呢 先说它的用法,举个例子 在语句 AlertDialog.Builder builder = new AlertDialog.Builder(this); 中,要求传递的参数就是一个context,在这里我们传入的是this,那么这个this究竟指的是什么呢? 这里的this指的是Activity.this,是这个语句所在的Activity的this,是这个Activity 的上下文。网上有很多朋友在这里传入this.getApplicationContext(),这是不对的。 AlertDialog对象是依赖于一个View的,而View是和一个Activity对应的。 于是,这里涉及到一个生命周期的问题,this.getApplicationContext()取的是这个应用程序的Context,Activity.this取的是这个Activity的Context,这两者的生命周期是不同的,前者的生命周期是整个应用

Android在Service中弹出对话框二

旧街凉风 提交于 2019-12-03 22:35:00
上一篇我也写了一篇弹窗的,但是经过测试,Android8.0之后用不了,所以改一下 Myservice.class package com.nf.service; import android.app.AlertDialog; import android.app.AliasActivity; import android.app.Dialog; import android.app.Service; import android.content.DialogInterface; import android.content.Intent; import android.os.Binder; import android.os.Build; import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.util.Log; import android.view.WindowManager; import android.widget.Toast; import java.sql.Time; import java.util.Objects; import java.util.Timer; import java.util.TimerTask; public

Not receiving GCM notifications once app is killed on Xiaomi and Lenovo devices in Android

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Can anyone help me to receive notifications on Xiaomi and Lenovo devices even after the app is killed(no more in the background)? Edit 1 I added GCM broadcast receiver. Here is the code inside AndroidManifest.xml <receiver android:name="com.don.offers.broadcast_receiver.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <!-- Receives the actual messages. --> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.google.android.gcm.demo.app" /> </intent

support.v7.app.AlertDialog throws NullPointerException on dismiss

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I updated AppCompat to the newly released revision 22.1.0 and changed my AlertDialog to support.v7.app.AlertDialog . But on a Lollipop device, it throws the following exception on dismissDialog() . java.lang.NullPointerException: attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference at android.support.v7.internal.app.WindowDecorActionBar.getDecorToolbar(WindowDecorActionBar.java:248) at android.support.v7.internal.app.WindowDecorActionBar.init(WindowDecorActionBar.java:201) at android

Custom Span Underline Text with Dotted line Android

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I was tiring to underline a specific word in the text with a dotted or dashed line with and also Clickable Span. I haven't found a solution can someone help me, please. SpannableStringBuilder sb = new SpannableStringBuilder(text); List listmot = new ArrayList(); listmot=db.getAlldef(); for(int i=0;i<listmot.size();i++) { String mot = (listmot.get(i)).get_mot(); final String def = (listmot.get(i)).get_definition(); Log.v(null, mot); Pattern p = Pattern.compile(mot, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(text); while (m.find()){ //

how to set contents of setSingleChoiceItems in onPrepareDialog?

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Guys, in onCreateDialog i have this: case DIALOG_REVIEW : { if ( bundle . containsKey ( "POSITION" )) { final int position = bundle . getInt ( "POSITION" ); ArrayList < String > alterNumbers = numbers . get ( position ); final String [] phoneNums = new String [ alterNumbers . size ()]; for ( int i = 0 ; i < alterNumbers . size (); i ++) { phoneNums [ i ] = alterNumbers . get ( i ); } AlertDialog . Builder dialog = new AlertDialog . Builder ( this ); dialog . setTitle ( names . get ( position ) + "'s number(s)" ); dialog .

how to set an onclick listener for an imagebutton in an alertdialog

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a layout with an ImageButton that is inflated in an AlertDialog, where/how should I set an onClick listener? Here's the code I tried using: ImageButton ib = (ImageButton) findViewById(R.id.searchbutton); ib.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(TravelBite.this, "test", Toast.LENGTH_SHORT).show(); } }); 回答1: Try to put like this in ur code e.g:-if your alertdialog's object is ad,then ImageButton ib = (ImageButton) ad.findViewById(R.id.searchbutton); ib.setOnClickListener

Does AlertDialog support WebView?

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to implement a AlertDialog with a Webview inside. public OnClickListener imageButtonViewOnClickListener = new OnClickListener() { public void onClick(View v) { LayoutInflater inflater = LayoutInflater.from(MyActivity.this); // error here View alertDialogView = inflater.inflate(R.layout.alert_dialog_layout, null); WebView myWebView = (WebView) findViewById(R.id.DialogWebView); myWebView.loadData(webContent, "text/html", "utf-8"); AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this); builder.setView

No permission for UID to access URI error on Android Application

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am building a simple app to select an image or take one from camera and crop it. However, it is throwing me this error java.lang.SecurityException: Uid 10076 does not have permission to uri 0 @ content://com.android.providers.media.documents/document/image%3A66 at android.os.Parcel.readException(Parcel.java:1546) at android.os.Parcel.readException(Parcel.java:1499) at android.app.ActivityManagerProxy.grantUriPermission(ActivityManagerNative.java:3948) at android.app.ContextImpl.grantUriPermission(ContextImpl.java:1961) at android.content

android activity has leaked window com.android.internal.policy.impl.phonewindow$decorview Issue

匿名 (未验证) 提交于 2019-12-03 02:19:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am working with Android application to show network error. NetErrorPage.java package exp.app; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class NetErrorPage extends Activity implements