码迷,mamicode.com
首页 > Windows程序 > 详细

4.PopupWindow

时间:2016-03-14 18:51:55      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

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

布局
 
<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);
	}

  

4.PopupWindow

标签:

原文地址:http://www.cnblogs.com/liuyu0529/p/5276612.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!