第十二章—PopupWindow
来源:互联网 发布:ubuntu如何卸载samba 编辑:程序博客网 时间:2024/06/05 03:09
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.administrator.popupwindowdemo.MainActivity"> <RelativeLayout android:id="@+id/rlS" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:layout_margin="50dp" android:background="@drawable/back" android:padding="5dp"> <EditText android:id="@+id/et_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:background="@null" android:hint="请输入电话号码" /> <ImageView android:id="@+id/iv_down" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:src="@mipmap/down_arrow" /> </RelativeLayout></RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="horizontal"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:src="@mipmap/user" /> <TextView android:id="@+id/tv_phone" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:text="电话" /> <ImageView android:id="@+id/iv_delete" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:src="@mipmap/delete" /></LinearLayout>
public class MainActivity extends AppCompatActivity implements View.OnClickListener {super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); for (int i = 0; i < 50; i++) { numbers.add("13815474" + i); } iv_down = (ImageView) findViewById(R.id.iv_down); et_content = (EditText) findViewById(R.id.et_content); rl = (RelativeLayout) findViewById(R.id.rlS); iv_down.setOnClickListener(this); } PopupWindow window; @Override public void onClick(View v) { ListView lv = new ListView(this); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { et_content.setText(numbers.get(position)); window.dismiss(); } }); lv.setAdapter(adapter); window = new PopupWindow(lv, rl.getWidth(), 200, true); window.setOutsideTouchable(true); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); window.showAsDropDown(rl, 0, 50); } private BaseAdapter adapter = new BaseAdapter() { @Override public int getCount() { return numbers.size(); } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(final int position, View convertView, ViewGroup parent) { ViewHodler holder; if (convertView == null) { convertView = View.inflate(getBaseContext(), R.layout.iten_layout, null); holder = new ViewHodler(convertView); convertView.setTag(holder); } else holder = (ViewHodler) convertView.getTag(); holder.tv_phone.setText(numbers.get(position)); holder.iv_delete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { numbers.remove(position); adapter.notifyDataSetChanged(); } }); return convertView; } class ViewHodler { TextView tv_phone; ImageView iv_delete; public ViewHodler(View convertView) { tv_phone = (TextView) convertView.findViewById(R.id.tv_phone); iv_delete = (ImageView) convertView.findViewById(R.id.iv_delete); } } };}
0 0
- 第十二章—PopupWindow
- 第十二章—Bitmap
- 第十二章—SurfaceView
- 第十二章—动画
- 第十二章—自定义属性
- 第十二章
- 第十二章
- 第十二章
- 第十二章
- 第十二章
- 第十二章..
- 第十二章
- 第十二章
- 第十二章
- 第十二章
- 第十二章——子类化UITableViewCell
- 第十二章—绘制路径Path
- 《APUE》读书笔记—第十二章线程控制
- Spring入门
- 【leetcode】63. Unique Paths II【java】
- 将Excel表格中的数据导出到xml文件中
- 互联网公司产品经理们面试的终极攻略
- 【leetcode】64. Minimum Path Sum【java】
- 第十二章—PopupWindow
- JAVA观察者模式
- 向android studio导入android源生app
- 数据库导出到EXAL 再供用户下载
- c语言函数指针
- 第十二章—SurfaceView
- Android学习21
- 停车场管理(栈和队列的应用)
- Object-C运行时(RunTime)机制访问隐藏成员变量