android弹出选择对话框-仿某团购网android客户端栏目选择
来源:互联网 发布:linux dns配置文件详解 编辑:程序博客网 时间:2024/06/07 01:01
转自:http://owftc.iteye.com/blog/1993283
效果图一:
效果图二:
未完善,还比较简单:
弹出对话框,先只显示左边列表,右边列表需要宽度设置为0,用visiable会影响使用。
选中左边列表时,再根据数据情况展现右边或者是选中提交。
PopupCategory.java
- package com.example.ysq.activity;
- import java.util.ArrayList;
- import java.util.List;
- import com.example.ysq.R;
- import com.example.ysq.adapter.CategoryAdapter;
- import com.example.ysq.entity.CategoryEntity;
- import android.os.Bundle;
- import android.util.DisplayMetrics;
- import android.view.Gravity;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.Window;
- import android.view.WindowManager;
- import android.widget.AdapterView;
- import android.widget.AdapterView.OnItemClickListener;
- import android.widget.LinearLayout.LayoutParams;
- import android.widget.ListView;
- import roboguice.fragment.RoboDialogFragment;
- import roboguice.inject.InjectView;
- public class PopupCategory extends RoboDialogFragment{
- @InjectView(R.id.rootcategory)
- private ListView rootcategory;
- @InjectView(R.id.childcategory)
- private ListView childcategory;
- @InjectView(R.id.child_lay)
- private View child_lay;
- private Window window;
- public int x,y;
- @Override
- public void onActivityCreated(Bundle savedInstanceState){
- super.onActivityCreated(savedInstanceState);
- this.rootcategory.setDrawSelectorOnTop(true);
- this.rootcategory.setVerticalScrollBarEnabled(false);
- this.childcategory.setDrawSelectorOnTop(true);
- this.childcategory.setVerticalScrollBarEnabled(false);
- final List<CategoryEntity> data=new ArrayList<CategoryEntity>();
- for(int i=0;i<20;i++){
- CategoryEntity e=new CategoryEntity();
- data.add(e);
- e.setSeq(i);
- e.setCount(i%3);
- e.setName("测试"+i);
- List<CategoryEntity> childList=new ArrayList<CategoryEntity>();
- e.setChildList(childList);
- for(int j=0;j<e.getCount();j++){
- CategoryEntity ce=new CategoryEntity();
- childList.add(ce);
- ce.setSeq(j);
- ce.setCount(j);
- ce.setName("子目录"+i+":"+j);
- }
- }
- final CategoryAdapter adapter=new CategoryAdapter(getActivity(), data, R.layout.category_item);
- rootcategory.setAdapter(adapter);
- final CategoryAdapter childadapter=new CategoryAdapter(getActivity(), new ArrayList<CategoryEntity>(), R.layout.category_child_item);
- childcategory.setAdapter(childadapter);
- rootcategory.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
- //用下面getChildAt会报异常,因为这个只能在手机屏幕可视范围内能获取到,超出返回null
- // View v;
- // Log.e("i:", parent.getCount()+"");
- // Log.e("i:", parent.getChildCount()+"");
- // for (int i = 0; i < parent.getChildCount(); i++) {
- // Log.e("i:", i+"");
- // v = parent.getChildAt(i);
- // if (position == i) {
- // v.setBackgroundColor(Color.argb(153, 0, 186, 255));
- // } else {
- // v.setBackgroundColor(Color.TRANSPARENT);
- // }
- // }
- adapter.setFocus(position);
- CategoryEntity category=data.get(position);
- List<CategoryEntity> childList=category.getChildList();
- if(childList.size()>0){
- childadapter.setData(childList);
- WindowManager.LayoutParams localLayoutParams;
- localLayoutParams=window.getAttributes();
- localLayoutParams.width = (int)(width-localLayoutParams.x*2);
- localLayoutParams.height = (int)(height-localLayoutParams.y*2);
- window.setAttributes(localLayoutParams);
- LayoutParams params=new LayoutParams((int)(width/2-localLayoutParams.x),localLayoutParams.height);
- child_lay.setLayoutParams(params);
- }else{
- //todo:
- PopupCategory.this.dismiss();
- }
- }
- });
- childcategory.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
- PopupCategory.this.dismiss();
- }
- });
- // child_lay.setVisibility(View.INVISIBLE);
- //设置宽度高度
- LayoutParams params=new LayoutParams(0, 0);
- child_lay.setLayoutParams(params);
- }
- private int height;
- private int width;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- window = this.getDialog().getWindow();
- WindowManager.LayoutParams localLayoutParams;
- window.setWindowAnimations(R.style.push_top);
- window.setBackgroundDrawableResource(R.drawable.bg_category);
- localLayoutParams=window.getAttributes();
- localLayoutParams.gravity=Gravity.TOP|Gravity.LEFT;
- localLayoutParams.x=this.x;
- localLayoutParams.y=this.y;
- window.addFlags(Window.FEATURE_PROGRESS);
- localLayoutParams.dimAmount=0.6F;
- DisplayMetrics displaymetrics = new DisplayMetrics();
- this.getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
- height = displaymetrics.heightPixels;
- width = displaymetrics.widthPixels;
- localLayoutParams.width = (int)(width/2-localLayoutParams.x);
- localLayoutParams.height = (int)(height-localLayoutParams.y*2);
- window.setAttributes(localLayoutParams);
- this.setCancelable(true);
- this.getDialog().setCanceledOnTouchOutside(true);
- View localView = inflater.inflate(R.layout.popup_category, container, false);
- return localView;
- }
- }
CategoryAdapter.java
- package com.example.ysq.adapter;
- import java.util.List;
- import com.example.ysq.R;
- import com.example.ysq.entity.CategoryEntity;
- import android.content.Context;
- import android.graphics.Color;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- public class CategoryAdapter extends BaseAdapter {
- private List<CategoryEntity> entityList;
- private LayoutInflater inflater;
- private int itemViewResource;
- private int index = 0;
- public CategoryAdapter(Context paramContext, List<CategoryEntity> entityList, int itemViewResource) {
- this.inflater = ((LayoutInflater) paramContext.getSystemService("layout_inflater"));
- this.entityList = entityList;
- this.itemViewResource = itemViewResource;
- }
- public void setData(List<CategoryEntity> paramList){
- this.entityList=paramList;
- notifyDataSetChanged();
- }
- private CategoryEntity b(int paramInt) {
- return (CategoryEntity) this.entityList.get(paramInt);
- }
- public final void setFocus(int index ) {
- this.index = index ;
- notifyDataSetChanged();
- }
- public final int getCount() {
- if (isNull(this.entityList))
- return 0;
- return this.entityList.size();
- }
- public final long getItemId(int paramInt) {
- return paramInt;
- }
- public final View getView(int paramInt, View paramView,
- ViewGroup paramViewGroup) {
- CategoryEntity localwk = b(paramInt);
- ListItemView itemView;
- if (paramView == null)
- {
- paramView = this.inflater.inflate(this.itemViewResource, paramViewGroup, false);
- itemView = new ListItemView();
- itemView.name = ((TextView)paramView.findViewById(R.id.name));
- itemView.count = ((TextView)paramView.findViewById(R.id.count));
- itemView.haschild = ((ImageView)paramView.findViewById(R.id.haschild));
- paramView.setTag(itemView);
- }else{
- itemView = (ListItemView)paramView.getTag();
- }
- if(this.itemViewResource==R.layout.category_item){//父结构
- if(localwk.getSeq()==this.index){
- paramView.setBackgroundColor(Color.argb(255,234,234,234));//#ffeaeaea
- }else{
- paramView.setBackgroundDrawable(null);
- }
- }
- itemView.name.setText(localwk.getName());
- if (localwk.getCount() != -1)
- itemView.count.setText(String.valueOf(localwk.getCount()));
- if (isNull(localwk.getChildList()))
- itemView.haschild.setVisibility(View.INVISIBLE);
- else
- itemView.haschild.setVisibility(View.VISIBLE);
- return paramView;
- }
- static class ListItemView
- {
- TextView name;
- TextView count;
- public ImageView haschild;
- }
- public <T> boolean isNull(List<T> paramList) {
- return (paramList == null) || (paramList.isEmpty());
- }
- @Override
- public Object getItem(int arg0) {
- // TODO Auto-generated method stub
- return null;
- }
- }
0 0
- android弹出选择对话框-仿某团购网android客户端栏目选择
- android弹出选择对话框-仿某团购网android客户端栏目选择
- android弹出抉择对话框-仿某团购网android客户端栏目选择
- android 时间选择对话框
- Android选择对话框
- Android--选择对话框--AlertDialog
- 弹出"选择文件夹"对话框
- C#弹出选择对话框
- 弹出选择颜色对话框
- 弹出文件夹选择对话框
- Android 关机弹出选择菜单
- Android 关机弹出选择菜单
- android弹出时间选择框
- android 弹出日期选择框
- android 弹出日期选择框
- Android 实现 选择文件对话框
- ANDROID 实现选择文件对话框
- ANDROID 实现选择文件对话框
- Android开发布局中margin和padding的区别以及文本的快速居中的方法
- pthread_key_t和pthread_key_create()详解
- Zepto 使用中的一些注意点
- 阿里腾讯投资快递只是第一步
- 如何单击某行使其颜色变化并且在单击其他行后颜色恢复
- android弹出选择对话框-仿某团购网android客户端栏目选择
- Lua4.0 实现#操作,获取table大小
- 提高篇第16-19课第四题
- linux之间传递文件
- 1.python学习第一天-爬取我的第一个网页
- Unity摄像机的使用二:摄像机的切换
- UIBezierPath
- Android-自定义图像资源的使用
- Android自动化测试工具对比