widget 點選事件 轉

2021-09-01 05:12:09 字數 2660 閱讀 9713

一、開啟activity

二、開始service

三、傳送按鈕action

下面開始乙個乙個分析,如何實現。

一、開啟activity

1、首先先定義個開啟activity的intent

eg:

intent fullintent=new intent(this,fullscreen.class);

若要傳遞資料,則使用intent.putextra()方法

eg: fullintent.putextra("iscircle",iscircle);

2、用intent例項化乙個pendingintent,呼叫pendingintent的getacticity方法來啟動另乙個activity

①若該intent帶有資料,則需要將最後乙個引數的值設為:flag_cancel_current

eg: pendingintent pfullintent=pendingintent.getactivity(this, 0, fullintent,pendingintent.flag_cancel_current);

②若該intent不帶資料,則最後乙個引數設為0

eg: pendingintent pfullintent=pendingintent.getactivity(this, 0, fullintent, 0);

3、例項化remoteview,其對應相應的widget布局

eg: remoteviews views= newremoteviews(getpackagename(), r.layout.widget);

4、給remoteview上的button或imagebutton設定按鈕事件

eg: views.setonclickpendingintent(r.id.ibfullscreen,pfullintent);

eg: public remoteviews views;//remoteview物件

publiccomponentname thiswidget; //元件名

二、開啟service

1、定義乙個intent來開啟service

eg: intent startserviceinten=newintent("zyf.temp.service.start");

注:引數為開啟service的動作

2、用intent例項化乙個pendingintent,利用pendingintent的getservice方法來啟動乙個服務

eg: pendingintent pintent=pendingintent.getservice(context, 0, startserviceinten, 0);

3、例項化remoteview,其對應相應的widget布局

eg: remoteviews views= newremoteviews(getpackagename(), r.layout.widget);

4、給remoteview上的button或imagebutton設定按鈕事件

eg: views.setonclickpendingintent(r.id.ibfullscreen,pfullintent);

eg: public remoteviews views;//remoteview物件

publiccomponentname thiswidget; //元件名

三、傳送按鈕action

1、定義乙個intent來傳送按鈕action

eg: intent previnten=new intent("prev");

2、用intent例項化乙個pendingintent,利用pendingintent的getbroadcast方法來傳送廣播

eg: pendingintent pprevintent=pendingintent.getbroadcast(this, 0, previnten, 0);

3、例項化remoteview,其對應相應的widget布局

eg: remoteviews views= newremoteviews(getpackagename(), r.layout.widget);

4、給remoteview上的button或imagebutton設定按鈕事件

eg: views.setonclickpendingintent(r.id.ibprev,pprevintent);

eg: public remoteviews views;//remoteview物件

publiccomponentname thiswidget; //元件名

6、接收該action

⒈在action,要在manifest.xml中加入action

⒉在onreceive()方法內編寫要實現的動作

eg: if(intent.getaction().equals("prev"))

②在service內接收

⒈註冊乙個broadcastreceive,宣告接收器

eg: intentfilter filter=new intentfilter();

filter.addaction("prev");

registerreceiver(docommand, filter);

⒉,在broadcastreceive類的onreceive方法內編寫要實現的動作

eg: if(intent.getaction().equals("prev"))

UIImageview 點選事件

uiimageview imageview uiimageview alloc initwithframe cgrectmake 100,100,200,200 imageview.image uiimage imagenamed filter laozhaopian a.png imageview...

Android view點選事件

import android.os.bundle import android.view.keyevent import android.view.motionevent import android.view.view import android.view.view.onclicklistene...

onclick 點選事件

1.開啟 name button1 2.另存為 name button2 3.屬性 name button3 4.列印 name button 5.頁面設定 name button4 6.重新整理 name refresh 7.匯入收藏夾 name button5 8.匯出收藏夾 name butt...