Android is similar to the implementation of QQ account login drop-down box (with source code), android drop-down box
// Set downArroImageView for popupWindow. setOnClickListener (new OnClickListener () {@ Override public void onClick (View arg0) {// defines popupWindow = new PopupWindow (MainActivity. this); // set the width of popupWindow. setWidth (inputEditText. getWidth (); // set the height of popupWindow. setHeight (200); // fill the popupWindow content with popupWindow. setContentView (listView); // click an area other than popupWindow to automatically close popupWindow. setOutsideTouchable (true); // set the position popupWindow in the pop-up window. showAsDropDown (inputEditText, 0, 0 );}});
// Initialize listviewprivate void initListView () {// TODO automatically generated method stub listView = new ListView (this); // sets the background color listView. setBackgroundResource (R. drawable. listview_background); // sets the delimiter to null listView. setDivider (null); // set the scroll bar to false listView. setVerticalScrollBarEnabled (false); listView. setAdapter (new MyListAdapter ());}
// MyListAdapterprivate class MyListAdapter extends BaseAdapter {@ Override public int getCount () {// return msgList, the method stub automatically generated by TODO. size () ;}@ Override public Object getItem (int arg0) {// return null, the method stub automatically generated by TODO;} @ Override public long getItemId (int arg0) {// return 0;} @ Override public View getView (final int arg0, View arg1, ViewGroup arg2) {// method stub ViewHolder houder automatically generated by TODO; if (arg1 = null) {arg1 = View. inflate (getApplicationContext (), R. layout. list_item, null); houder = new ViewHolder (); houder. deleteImageView = (ImageView) arg1.findViewById (R. id. delete); houder. TV _msgTextView = (TextView) arg1.findViewById (R. id. TV _list_item); arg1.setTag (houder);} else {houder = (ViewHolder) arg1.getTag ();} houder. TV _msgTextView.setText (msgList. get (arg0); houder. deleteImageView. setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {// Delete the corresponding entry msgList. remove (arg0); // refresh listview MyListAdapter. this. notifyDataSetChanged () ;}}); arg1.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {// you can specify inputEditText in the input box. setText (msgList. get (arg0); // hide PopupWindow popupWindow. dismiss () ;}}); return arg1 ;}} private class ViewHolder {TextView TV _msgTextView; ImageView deleteImageView ;}
Source code download
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.