2012-02-24 11 views
1

ダイアログを開くときに次のアンドロイド例外が発生します。自分のSoftKeyboardキーを押しているときにこの問題を解決するにはどうしたらいいですか?自分のソフトキーボードキーを押したときにダイアログを追加できません

BadTokenException: Unable to add window -- token null is not for an application 
com.example.android.softkeyboard.SoftKeyboard.diqalog(SoftKeyboard.java:759) 
com.example.android.softkeyboard.SoftKeyboard.onKey(SoftKeyboard.java:526) 
android.inputmethodservice.KeyboardView.onModifiedTouchEvent(KeyboardView.java:1252) 
+0

あなたのコードを貼り付けます。 –

+0

CharSequence [] items = {"Red"、 "Green"、 "Blue"}; mCurKeyboard = simleyKey; mInputView.setKeyboard(mCurKeyboard); mInputView.closing(); AlertDialog.Builder builder =新しいAlertDialog.Builder(this); builder.setTitle( "色を選択"); builder.setItems(項目、新規DialogInterface.OnClickListener(){ 公共ボイドのonClick(DialogInterfaceダイアログ、INTアイテム){ Toast.makeText(getApplicationContext()、アイテム[アイテム]、Toast.LENGTH_SHORT).SHOW(); } })。show(); –

+0

あなたの質問に書式設定されたコードを与え、TAb BArを使用していますか? –

答えて

1

まず第一に、あなたはBadTokenExceptionを取得している理由です、あなただけのランニングActivity内から行うことができ、リモートサービスからダイアログを提示することはできません。

1)ActivityTheme.Dialogとテーマ現在::

<activity 
     android:name="com.srgtuszy.activity" 
     android:theme="@android:style/Theme.Dialog" 
     /> 

をまた、新しいタスクとしての活動を開始します。

Intent intent = new Intent(context, MyActivity.class); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(intent); 

この方法であなたは、しかし、この問題の解決策がありますダイアログのように見えるアクティビティが得られます。

2)空と透明Activityを提示し、

宣言活動の中からAlertDialogを示し、以前と同じようにマニフェストに活動を開始したが、透明なテーマを使用します。

<style name="Theme.Transparent" parent="android:Theme"> 
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:windowBackground">@android:color/transparent</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowIsFloating">true</item> 
    <item name="android:backgroundDimEnabled">false</item> 
    </style> 

をこのアクティビティでonCreate()メソッドを無効にして、setContentView()とし、AlertDialogとしてください。

@Override 
protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    Context context = this; 
    AlertDialog.Builder dialog = new AlertDialog.Builder(context); 
    dialog.setTitle("Hello!"); 
    dialog.show(); 
} 

これはもっと面倒なアプローチですが、この方法では、入力メソッドを無視しないでユーザーにダイアログを表示できます。たとえば、編集オプションを表示するために使用できます。

特定のイベントについてユーザーに通知したい場合は、Notificationsを使用することを検討してください。ユーザーが気を散らしてUIを汚染することはありません。

+0

hei、良い答え、InpuntMethodServiceに結果を戻す方法はありますか? – Apperside

関連する問題