ウィジェットで複数ボタンを制御したい
ウィジェットはシンプルに作成したい。
でも機能的にどうしても複数のボタンをつける必要が出てきちゃいました。
サンプルソース
単純に、インテントを2種類作成すれば実現できます。
private static final String ACTION_BTNCLICK = “*****Service.ACTION_BTNCLICK”; private static final String ACTION_BTNCLICK2 = “*****Service.ACTION_BTNCLICK2”;Intent newintent = new Intent(); newintent.setAction(ACTION_BTNCLICK); PendingIntent pending = PendingIntent.getService(this,0,newintent,0); view.setOnClickPendingIntent(R.id.button1,pending); if (ACTION_BTNCLICK.equals(intent.getAction())) { btnClicked(view); } Intent newintent2 = new Intent(); newintent2.setAction(ACTION_BTNCLICK2); PendingIntent pending2 = PendingIntent.getService(this,0,newintent2,0); view.setOnClickPendingIntent(R.id.button2,pending2); if (ACTION_BTNCLICK2.equals(intent.getAction())) { btnClicked2(view); } |
<service android:name=”*****Service”> <intent-filter> <action android:name=”*****Service.ACTION_BTNCLICK”/> <action android:name=”*****Service.ACTION_BTNCLICK2″/> </intent-filter> </service> |
ブログ記事について
記事は毎週月曜日午前中に発信!(私感/私考カテゴリについては随時)
多数の投稿記事は、メニューや検索機能で目的の記事に辿る事が可能です。
コメントや下記支援のご協力をお願い致します。
公式ホームページについて
当ブログではITエンジニア関連のテクニカルな事、そして様々な商品のレビュー記事を公開しています。
一方ホームページでは、それ以外の少しビジネス寄り(企業や個人事業主向け)のサービスや情報を発信します。
該当される方、ご興味のある方はホームページの方もご参照ください。