zoukankan      html  css  js  c++  java
  • PopupWindow的使用

    想要弹出内容就可以考虑使用悬浮窗

    布局
     
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/rl_root"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context=".LoginActivity" >
        <com.handmark.pulltorefresh.library.PullToRefreshListView
            android:id="@+id/lv_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#fff" />
        <View
            android:id="@+id/viewHolder"
            android:layout_width="match_parent"
            android:layout_height="53dp"
            android:visibility="gone" />
    </LinearLayout>
    

     代码

    	lv_list.setOnItemLongClickListener(new OnItemLongClickListener() {
    			@Override
    			public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    				Toast.makeText(getApplicationContext(), "长按", 0).show();
    				//开启编辑模式
    				startEditModel();
    				if (position > 0) {
    					position -= 1;
    				}
    				adapter.toggleSelect(view, position);
    				return true;
    			}
    		});
    	}
    	private boolean isEditModel;
    	private int seletedCount;
    
    	/**
    	 * 开启编辑模式
    	 */
    	private void startEditModel() {
    		//listview需要刷新
    		isEditModel = true;
    		adapter.notifyDataSetChanged();
    		//修改actionbar
    		uploadMenuItem.setVisible(false);
    		downloadMenuItem.setVisible(false);
    		moreMenuItem.setVisible(false);
    		selectMenuItem.setVisible(true);
    		actionBar.setDisplayHomeAsUpEnabled(true);
    		actionBar.setTitle(String.format("已选定%d个", seletedCount));
    		//显示底部的popupwindows
    //当在最 底部时会覆盖条目,可以在下面弄个view,让他显示
    		showBottomPopupWindow();
    		//listview上移
    		viewHolder.setVisibility(0);
    	}
    	/**
    	 * 结束编辑模式
    	 */
    	private void stopEditModel() {
    		//listview需要刷新
    		isEditModel = false;
    		adapter.notifyDataSetChanged();
    		//修改actionbar
    		uploadMenuItem.setVisible(true);
    		downloadMenuItem.setVisible(true);
    		moreMenuItem.setVisible(true);
    		selectMenuItem.setVisible(false);
    		actionBar.setTitle("黑马网盘");
    		//返回按钮的处理
    		if ("/".equals(curPath)) {
    			actionBar.setDisplayHomeAsUpEnabled(false);
    		}
    		//隐藏popupwindows
    		bottomPopupWindow.dismiss();
    		//listview还原
    		viewHolder.setVisibility(8);
    		//还原entryWrapper的选中状态
    		for (EntryWrapper entryWrapper : contents) {
    			entryWrapper.isCheck = false;
    		}
    		seletedCount = 0;
    	}
    	private void showBottomPopupWindow() {
    		if (bottomPopupWindow == null) {
    			View contentView = View.inflate(MainActivity.this, R.layout.bottom_edit_pop, null);
    			int width = ViewGroup.LayoutParams.FILL_PARENT;
    			int height = ViewGroup.LayoutParams.WRAP_CONTENT;
    			bottomPopupWindow = new PopupWindow(contentView, width, height);
    			contentView.findViewById(R.id.DeleteBtn).setOnClickListener(new OnClickListener() {
    				@Override
    				public void onClick(View v) {
    					List<EntryWrapper> selectedEntryWrappers = new ArrayList<EntryWrapper>();
    					for (EntryWrapper info : contents) {
    						if (info.isCheck) {
    							selectedEntryWrappers.add(info);
    						}
    					}
    					StringBuffer sb = new StringBuffer();
    					//遍历输出
    					for (EntryWrapper entryWrapper : selectedEntryWrappers) {
    						sb.append(entryWrapper.entry.fileName()).append(" ");
    					}
    					System.out.println(sb.toString());
    				}
    			});
    		}
    		bottomPopupWindow.showAtLocation(rl_root, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    	}
    

      

  • 相关阅读:
    keep-alive的深入理解与使用(配合router-view缓存整个路由页面)
    vue无法自动打开浏览器
    解决vue页面刷新或者后退参数丢失的问题
    vue 跳转并传参,实现数据实时更新
    Struts2 有关于无法正常的使用通配符
    有关于java反编译工具的使用
    Action名称的搜索顺序
    Struts2 的 值栈和ActionContext
    在Action 中访问web资源
    oracle 创建database Link
  • 原文地址:https://www.cnblogs.com/sixrain/p/5276612.html
Copyright © 2011-2022 走看看