PopupWindow (zhong pin)

import android.content.Context; import android.graphics.Color; import android.graphics.Typeface; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View.OnClickListener; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.TextView; import android.widget.LinearLayout.LayoutParams; import com.android.archermind.activity.R; public class PopupWindowHelper { private Context context; // 当前所在Activity的布局ID private int layout; // 当前所在Activity的监听类(OnClickListener) private OnClickListener listener; private PopupWindow pw; // 当前所在Activity的最外层布局组件的ID private int view; // PopupWindow所在的y轴坐标 private int y; // PopupWindow的整体高度 private int height; // PopupWindow中的数据(绘制每一项) private String[][] datas; // PopupWindow中的分割线的数目 private int lineCount; // 设置TextView的ID(可以设置初始值) private int id = 0; public PopupWindowHelper(Context context, int layout, OnClickListener listener, int view, int y, int height, String[][] datas, int lineCount, int id){ this.context = context; this.layout = layout; this.listener = listener; this.view = view; this.y = y; this.height = height; this.datas = datas; this.lineCount = lineCount; this.id = id; } /** * 弹出菜单窗口 */ public PopupWindow createPopupWindow() { LinearLayout pwLayout = new LinearLayout(this.context); for(int i = 0; i < datas.length; i++) { String[] text = datas[i]; if(i < lineCount) { initTextViewLayoutForPopup(text, pwLayout, true); } else { initTextViewLayoutForPopup(text, pwLayout, false); } } String inflater = Context.LAYOUT_INFLATER_SERVICE; LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(inflater); LinearLayout linearLayout = (LinearLayout) layoutInflater.inflate(this.layout, null); if(pw == null) { pw = new PopupWindow(pwLayout); pw.showAtLocation(linearLayout.findViewById(this.view), Gravity.CENTER,0,0); } else if(!pw.isShowing()) { pw.showAtLocation(linearLayout.findViewById(this.view), Gravity.CENTER,0,0); } pw.update(-101, this.y, 161, this.height); return pw; } /** * 动态加载PopupWindow的界面(用于MENU) * @param texts * @param pwLayout * @param isNeedLine */ private void initTextViewLayoutForPopup(String[] texts, LinearLayout pwLayout, Boolean isNeedLine) { pwLayout.setOrientation(LinearLayout.VERTICAL); pwLayout.setBackgroundResource(R.drawable.popup_bg); for(int i = 0; i < texts.length; i++, id++){ TextView textView = new TextView(context); textView.setTextColor(Color.parseColor("#FFFFFF")); textView.setText(texts[i]); textView.setTypeface(null, Typeface.BOLD); textView.setPadding(10, 4, 0, 4); textView.setId(id); textView.setOnClickListener(this.listener); pwLayout.addView(textView, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } if(isNeedLine) { ImageView line = new ImageView(context); line.setImageResource(R.drawable.pop_line); line.setPadding(5, 5, 0, 0); pwLayout.addView(line, new LinearLayout.LayoutParams(135, LayoutParams.WRAP_CONTENT)); } } }

输入监听:

EditText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { showInstantResultList(); }

更多相关文章

  1. android短信监听
  2. ArcGIS for Android(安卓)Runtime100 基本操作(四)——GPS定位
  3. Android(安卓)事件处理详解(一) —— 基于监听的事件处理 1
  4. Android(安卓)单独控件实现不同字体大小、不同颜色
  5. Android-注册界面
  6. 极光推送获取不到RegisterId(注册ID)Android
  7. android 简单实用的Log打印类封装,助你快速定位问题
  8. Android(安卓)RecyclerView左划删除和长按删除
  9. 通过网络使用ADB ( Connect to android with ADB over TCP )

随机推荐

  1. Android零点一度的区别——Matrix
  2. Android(安卓)Studio学习路程(6)
  3. android获取位图
  4. Android 禁止屏幕旋转 & 屏幕旋转不刷新
  5. Android 中 画图与动画旋转效果(中级)
  6. Android -- getSystemService
  7. Android(安卓)Fragment+ViewPager禁止Vie
  8. flex 4.5 开发android 的文章
  9. Android 屏幕方向以及UI界面状态的保存
  10. Android多语言与国际化