Android開(kāi)發(fā)中PopupWindow用法實(shí)例分析
本文實(shí)例分析了Android開(kāi)發(fā)中PopupWindow用法。分享給大家供大家參考,具體如下:
private TextView tv_appmanager_title;
private ListView lv_app_manager;
private LinearLayout ll_appmanager_loading;
private AppManagerProvider provider;
private List<AppManagerInfo> infos ;
private AppManagerAdapter adapter;
private PopupWindow localPopupWindow;
private Handler handler = new Handler(){
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case Constants.MSG_APP_MANAGER:
ll_appmanager_loading.setVisibility(View.INVISIBLE);
adapter = new AppManagerAdapter(infos, AppManagerActivity.this);
lv_app_manager.setAdapter(adapter);
break;
}
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.appmanager);
lv_app_manager = (ListView) this.findViewById(R.id.lv_app_manager);
ll_appmanager_loading = (LinearLayout) this.findViewById(R.id.ll_appmanager_loading);
ll_appmanager_loading.setVisibility(View.VISIBLE);
new Thread(){
public void run() {
provider = new AppManagerProvider(AppManagerActivity.this);
infos = provider.getAppManagerInfo();
Message msg = new Message();
msg.what = Constants.MSG_APP_MANAGER;
handler.sendMessage(msg);
};
}.start();
lv_app_manager.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(null != localPopupWindow){
localPopupWindow.dismiss();
localPopupWindow = null;
}
int [] location = new int[2];
view.getLocationInWindow(location);
int x = location[0] + 60;
int y = location[1];
TextView tv = new TextView(AppManagerActivity.this);
AppManagerInfo info = (AppManagerInfo) lv_app_manager.getItemAtPosition(position);
tv.setText(info.getPackName());
tv.setTextSize(20);
tv.setTextColor(Color.RED);
localPopupWindow = new PopupWindow(tv, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
Drawable background = new ColorDrawable(Color.GRAY);
localPopupWindow.setBackgroundDrawable(background);
localPopupWindow.showAtLocation(tv, 51, x, y);
}
});
lv_app_manager.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if(null != localPopupWindow){
localPopupWindow.dismiss();
localPopupWindow = null;
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if(null != localPopupWindow){
localPopupWindow.dismiss();
localPopupWindow = null;
}
}
});
}
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開(kāi)發(fā)入門與進(jìn)階教程》、《Android通信方式總結(jié)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。
- Android編程實(shí)現(xiàn)popupwindow彈出后屏幕背景變成半透明效果
- Android Animation實(shí)戰(zhàn)之屏幕底部彈出PopupWindow
- Android編程之ICS式下拉菜單PopupWindow實(shí)現(xiàn)方法詳解(附源碼下載)
- android使用PopupWindow實(shí)現(xiàn)頁(yè)面點(diǎn)擊頂部彈出下拉菜單
- Android PopupWindow使用實(shí)例
- Android PopupWindow 點(diǎn)擊外面取消實(shí)現(xiàn)代碼
- Android中PopupWindow響應(yīng)返回鍵并關(guān)閉的2種方法
- Android入門之PopupWindow用法實(shí)例解析
- android教程之使用popupwindow創(chuàng)建菜單示例
- Android之用PopupWindow實(shí)現(xiàn)彈出菜單的方法詳解
- android popwindow實(shí)現(xiàn)左側(cè)彈出菜單層及PopupWindow主要方法介紹
- android PopupWindow 和 Activity彈出窗口實(shí)現(xiàn)方式
相關(guān)文章
flutter升級(jí)3.7.3報(bào)錯(cuò)Unable?to?find?bundled?Java?version解決
這篇文章主要介紹了flutter升級(jí)3.7.3報(bào)錯(cuò)Unable?to?find?bundled?Java?version解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加2023-02-02
React Native學(xué)習(xí)之Android的返回鍵BackAndroid詳解
這篇文章主要給大家介紹了關(guān)于React Native學(xué)習(xí)之Android的返回鍵BackAndroid的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用React Native具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起看看吧。2017-10-10
基于Flutter實(shí)現(xiàn)按位置大小比例布局的控件
做視頻監(jiān)控項(xiàng)目時(shí)需要需要展示多分屏,比如2x2、3x3、414等等,所以本文為大家介紹了如何基于Flutter實(shí)現(xiàn)按位置大小比例布局的控件,需要的可以參考一下2023-08-08
Android下拉刷新控件SwipeRefreshLayout源碼解析
這篇文章主要為大家詳細(xì)解析Android下拉刷新控件SwipeRefreshLayout源碼,感興趣的小伙伴們可以參考一下2016-07-07
android studio git 刪除已在遠(yuǎn)程倉(cāng)庫(kù)的文件或文件夾方式
這篇文章主要介紹了android studio git 刪除已在遠(yuǎn)程倉(cāng)庫(kù)的文件或文件夾方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04
Android使用Intent傳大數(shù)據(jù)簡(jiǎn)單實(shí)現(xiàn)詳解
這篇文章主要為大家介紹了Android使用Intent傳大數(shù)據(jù)簡(jiǎn)單實(shí)現(xiàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
Android 進(jìn)度條顯示在標(biāo)題欄的實(shí)現(xiàn)方法
android進(jìn)度條顯示在標(biāo)題欄的實(shí)現(xiàn)方法,大概分文xml文件和java文件,具體代碼內(nèi)容大家可以通過(guò)本文學(xué)習(xí)下2017-01-01

