2011-07-10 9 views
2

ユーザーが通知アイテムをクリックしたときに、アクティビティ(RluSvcMenu)のインテントがサービスから呼び出されます。 RluSvcMenuは、3つのオプションボタン([コピー/次へ]、[次へ]、[終了])を持つカスタムダイアログボックスを正常に表示します。 3つのボタンのいずれかがクリックされたときに、リスナー機能が呼び出されないようであることを除いて、すべて正常です。ボタンクリック時にAndroid OnClickListnerが呼び出されない

package com.lovelady.android.RluApp; 

import android.app.Activity; 
import android.app.Dialog; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.ImageView; 
import android.widget.TextView; 
import android.widget.Toast; 

public class RluSvcMenu extends Activity implements OnClickListener { 
    private int action; 
    private Button btnCopyNext; 
private Button btnNext; 
    private Button btnQuit; 
private final int SVC_MENU_DIALOG = 1; 
    private Dialog dialog; 
    private final String MY_TAG = "RluSvcMenu"; 
    private final String MESSAGE1 = "onCreate message"; 
    private final String MESSAGE2 = "onPrepare message"; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    showDialog(SVC_MENU_DIALOG); 
    Log.d(MY_TAG, "showDialog() has completed."); 
} 


    protected Dialog onCreateDialog(int id) { 
     dialog = new Dialog(this); 

     dialog.setContentView(R.layout.rlu_service_menu); 

     dialog.setTitle("RLU_APP"); 

     TextView text = (TextView) dialog.findViewById(R.id.text); 
     text.setText(MESSAGE1); 

     ImageView image = (ImageView) dialog.findViewById(R.id.icon); 
    image.setImageResource(R.drawable.ic_rlu); 

    btnCopyNext = (Button) dialog.findViewById(R.id.BtnCopyNext); 
    btnCopyNext.setOnClickListener(this); 

     btnNext = (Button) dialog.findViewById(R.id.BtnNext); 
    btnNext.setOnClickListener(this); 

    btnQuit = (Button) dialog.findViewById(R.id.BtnQuit); 
    btnQuit.setOnClickListener(this); 
    return dialog; 
} 

public void onClick(View v) { 
    action = v.getId() ; 
    Toast.makeText(getApplicationContext() 
      , "Button " + action + " clicked." 
      , Toast.LENGTH_SHORT).show(); 
    Log.d(MY_TAG, "Button " + action + " clicked."); 
    dialog.dismiss(); 
} 


protected void onPrepareDialog(int id, Dialog dialog) { 

    dialog.setContentView(R.layout.rlu_service_menu); 

    TextView text = (TextView) dialog.findViewById(R.id.text); 
    text.setText(MESSAGE2); 
    ImageView image = (ImageView) dialog.findViewById(R.id.icon); 
    image.setImageResource(R.drawable.ic_rlu_app); 
} 
} 

"サービスメニュー" を構築するためのXMLは次のとおりです:ここでRluSvcMenuコードの関連部分です

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/layout_root" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:padding="4dp" 
      > 
<ImageView android:id="@+id/icon" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="10dp" 
      /> 
<TextView android:id="@+id/text" 
      android:layout_width="wrap_content" 
      android:layout_toRightOf="@+id/icon" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="20dp" 
      android:textColor="#FFF" 
      /> 
<Button android:layout_height="wrap_content" 
     android:layout_below="@+id/text" 
     android:layout_toRightOf="@+id/icon" 
     android:layout_width="wrap_content" 
     android:id="@+id/BtnCopyNext" 
     android:text="Copy/Next"></Button> 
<Button android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/BtnCopyNext" 
     android:layout_below="@+id/text" 
     android:layout_width="wrap_content" 
     android:id="@+id/BtnNext" 
     android:text="Next"></Button> 
<Button android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/BtnNext" 
     android:layout_below="@+id/text" 
     android:layout_width="wrap_content" 
     android:id="@+id/BtnQuit" 
     android:text="Quit"></Button> 
</RelativeLayout> 

...そして最後に、AndroidManifest.xmlには次のようになります。

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.lovelady.android.AppName" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="7" /> 

    <application android:label="@string/app_name" 
       android:icon="@drawable/ic_mainIcon"> 
     <activity android:name=".RluSvcMenu"></activity> 
     <activity android:name=".RluOverview" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
      <!-- enable the search dialog to send searches to RluSearch --> 
      <meta-data android:name="android.app.default_searchable" 
         android:value=".RluSearch" /> 
     </activity> 
     <activity android:name=".RluDetails"></activity> 
     <activity android:name=".RluImportFile"></activity> 
     <activity android:name=".RluImportFilteredFile"></activity> 
     <activity android:name=".RluSearch"> 
      <intent-filter> 
       <action android:name="android.intent.action.SEARCH" /> 
      </intent-filter> 
      <meta-data android:name="android.app.searchable" 
         android:resource="@xml/searchable" /> 
     </activity> 
     <service android:name=".RluManager" 
       android:exported="false" 
       android:label="@string/service_name"> 
     </service> 
    </application> 
</manifest> 

アクティビティに届かない原因となるものは何ですか?彼らは代わりにサービスに行くのですか?もしそうなら、私はフォーカスを得るために何ができますか? (私はダイアログを置くことによって、フォーカスを取得したいと思ったが、唯一の手掛かりは、私は、logcatから、示しています

07-09 21:04:20.060 I/InputDispatcher( 302): Delivering touch to current input \ 
        target: action: 0, channel '409079b8 Rluapp (server)' 

(「Rluappは、」@文字列/ MY_APPの値、および名前ですパッケージのボタンが押されたときに)

...または何穴私は私のリスナーに記入するのを忘れたのか?すべての意図や目的のためには「何も」起こりません。

答えて

1

うーん、私はダイアログが実行されている疑いがあります別のスレッドではどうでしょうか?とにかく、あなたがDialogInterface.onClickListenerクラスを持っているので、問題を克服し、変更する方が良いでしょうコードと実際のカスタムダイアログでこれが修正されます。ここで

その修正と変更あなたの元のコードであるあなたは、それ自身のファイル/クラスでダイアログを置くことができるので、これはとにかく、おそらく優れているなど

public class BtnNoWorky extends Activity { 
    private int action; 
    private Button btnCopyNext; 
    private Button btnNext; 
    private Button btnQuit; 
    private final int SVC_MENU_DIALOG = 1; 
    private final String MY_LABEL = "BtnNoWorky"; 
    private final String MESSAGE1 = "Msg from onCreateDialog"; 
    private final String MESSAGE2 = "Msg from onPrepare"; 
    private myDialog D = null; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     Log.d(MY_LABEL, "onCreate()"); 
     super.onCreate(savedInstanceState); 

     Log.d(MY_LABEL, "Show dialog") ; 
     //showDialog(SVC_MENU_DIALOG); 
     D = new myDialog(this); 
     D.show(); 

     Log.d(MY_LABEL, "showDialog() has completed."); 
    } 

    public class myDialog extends Dialog implements OnClickListener { 

    public myDialog(Context context) { 
      super(context,0); 
    } 

    public myDialog(Context context, int theme) { 
      super(context, theme); 
    } 

    protected myDialog(Context context, boolean cancelable, OnCancelListener cancelListener) { 
      super(context, cancelable, cancelListener); 
      // TODO Auto-generated constructor stub 
     } 

    public void onCreate(Bundle saved) { 
     //Log.d(MY_LABEL, "onCreateDialog - Creating dialog"); 

     //Log.d(MY_LABEL, "onCreateDialog - setContentView"); 
     setContentView(R.layout.bnw_dialog); 

     //Log.d(MY_LABEL, "onCreateDialog - setTitle"); 
     setTitle("BtnNoWorky"); 

     //Log.d(MY_LABEL, "onCreateDialog - setText"); 
     TextView text = (TextView) findViewById(R.id.text); 
     text.setText(MESSAGE1); 

     //Log.d(MY_LABEL, "onCreateDialog - setImageResource"); 
     ImageView image = (ImageView) findViewById(R.id.icon); 
     image.setImageResource(R.drawable.icon); 

     //Log.d(MY_LABEL, "onCreateDialog - Instantiate btnCopyNext"); 
     btnCopyNext = (Button)findViewById(R.id.BtnCopyNext); 
     btnCopyNext.setOnClickListener(this); 

     //Log.d(MY_LABEL, "onCreateDialog - Instantiate btnNext"); 
     btnNext = (Button) findViewById(R.id.BtnNext); 
     btnNext.setOnClickListener(this); 

     //Log.d(MY_LABEL, "onCreateDialog - Instantiate btnQuit"); 
     btnQuit = (Button)findViewById(R.id.BtnQuit); 
     btnQuit.setOnClickListener(this); 

     //Log.d(MY_LABEL, "onCreateDialog - Returning..."); 


    } 

    @Override 
    public void onClick(View v) { 
     action = v.getId() ; 
     Toast.makeText(getApplicationContext() 
       , "Button " + action + " clicked." 
       , Toast.LENGTH_SHORT).show(); 
     Log.d(MY_LABEL, "Button " + action + " clicked."); 
     dismiss(); 
    } 
    } 

} 
+0

グッドキャッチ、@Idisticが、どうやらそれはありません唯一の問題。私は応答を感謝し、今私は一歩近づいていると信じています。ありがとう。 – Dennis

+0

これがサービスの問題なのかどうかを判断するために、私は同じ問題を抱えている超簡単なスタンドアロンのアプリケーションに問題Activityを突きつけました。しかし今、私は共有することができます...完全なEclipseプロジェクトは、[link](http://www.lovelady.com/misc/BtnNoWorky.zip)で、彼ら自身のために見たい人のためです。助けてくれてありがとうと思います。 – Dennis

+0

@Dennisこれはダイアログではありませんでした。それをクラスに変更すると、上記の元の答えにコードを追加して動作するはずです。ブレークポイントにヒットします – Idistic

関連する問題