查询条件样式的PopWindow
来源:互联网 发布:淘宝网钢琴防潮管 编辑:程序博客网 时间:2024/05/16 17:10
popwind在Android项目中用到的非常多今天就写一下我在项目中使用的情况,以后方便使用,下面直接上代码。
当点击城市模块的布局时候响应
ll_city.setOnClickListener(this);执行以下操作
//城市case R.id.ll_city: View view = LayoutInflater.from(this).inflate(R.layout.popup_area, null); lv_city = (ListView) view.findViewById(R.id.lv_area); initPopwind(view,ll_city); CityAdapter cityAdapter = new CityAdapter(this, cityList); lv_city.setAdapter(cityAdapter); //城市点击事件 lv_city.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { popupWindow.dismiss(); CityAdapter adapter = (CityAdapter) (parent.getAdapter()); //根据左侧一级分类选中情况,更新背景色 adapter.setSelectedPosition(position); adapter.notifyDataSetChanged(); tv_city.setText(cityList.get(position).getCity_name()); //请求最新数据 city_id = cityList.get(position).getCity_id(); requestData(province_id, city_id, 0); } }); break;初始化popwind,设置popwind的高度为屏幕的百分之60
private void initPopwind(View view, final View ll_view) { LinearLayout layout = new LinearLayout(PartyActivity.this); WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, (int) (screenHeight * 0.6)); view.setLayoutParams(params); layout.addView(view); layout.setBackgroundColor(Color.argb(60, 0, 0, 0));//设置整个popwind的底色有透明覆盖效果 popupWindow = new PopupWindow(layout, screenWidth, screenHeight); popupWindow.setFocusable(true); popupWindow.setBackgroundDrawable(new BitmapDrawable()); popupWindow.setOutsideTouchable(true); layout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { popupWindow.dismiss(); } }); popupWindow.showAsDropDown(ll_view);}popwind所加载的布局文件,你可以根据自己的需求更改,我需要展示的是城市列表所以写成了listview
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/lv_area" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:divider="@color/liner_color_grag" android:dividerHeight="1dp" android:background="#fff"/></LinearLayout>城市listview的adapter适配器
/** * 城市的adapter * Created by wss. */public class CityAdapter extends BaseAdapter{ private Context context; private List<CityBean> list; public CityAdapter(Context context, List<CityBean> list){ this.context = context; this.list = list; } @Override public int getCount() { return list==null?0:list.size(); } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView==null){ holder = new ViewHolder(); convertView = LayoutInflater.from(context).inflate(R.layout.right_listview_item, null); holder.nameTV = (TextView) convertView.findViewById(R.id.right_item_name); convertView.setTag(holder); }else{ holder = (ViewHolder) convertView.getTag(); } holder.nameTV.setText(list.get(position).getCity_name()); return convertView; } private int selectedPosition = 0; public void setSelectedPosition(int selectedPosition) { this.selectedPosition = selectedPosition; } public int getSelectedPosition() { return selectedPosition; } private class ViewHolder{ TextView nameTV; }}listview条目的布局文件,我这个写的布局很简单,自己可以根据需要写,如果是布局已经定好,条目固定而且数量有限就可以不用使用listview了,也就不需要adapter和条目的布局文件了。
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="45dp" > <TextView android:id="@+id/right_item_name" android:layout_width="match_parent" android:layout_height="45dp" android:textSize="14sp" android:textColor="@color/province" android:text="安钢" android:maxLength="10" android:ellipsize="end" android:gravity="center_vertical" android:background="@color/lv_bg" android:paddingLeft="10dp" /></LinearLayout>popwind代码写完了效果如下:
这个效果需要加上siderbar,下一篇博客会介绍这个功能
popwind效果如上图,希望能帮到大家。
0 0
- 查询条件样式的PopWindow
- oracle分区 前台查询条件样式
- 调用条件样式的方法
- sql的查询条件
- HBase的条件查询
- HBase的条件查询
- 复杂条件的查询
- HBase的条件查询
- Hibernate的条件查询
- 查询条件的拼接
- hql的条件查询
- Linq的条件查询
- 查询条件解析类,生成查询语句的查询条件
- dropload.js中条件查询时,刷新样式增多问题。
- 【Popwindow】自定义popwindow的底部间隙问题
- 多条件查询的sql
- ibatis 的多条件查询
- 多条件查询的程序
- 通过中序遍历、后序遍历求先序遍历
- CTA策略:主力连续、全合约模式下回测结果的差异探讨
- Vue H5 History 部署IIS上404问题
- 经典算法求字符串的编辑距离
- 实用站点收集——持续更新
- 查询条件样式的PopWindow
- Spark2.1.0文档:Spark Streaming 编程指南(上)
- 与64位版本的Windows不兼容,masm运行不了
- effective C++ 使用条款(一)——item1~item33总结
- 64位Ubuntu14.04系统下加载内核模块hello world
- Markdown 搬运整理
- HTML标签元素分类(HTML基础知识)
- linux下安装greeplum数据库基本操作
- querySelector与getElementBy等的区别