Drop-down Quick Select component
I believe everyone has the most recent login using QQ dropdown box, click to show the effect of recent login, click the option can submit content to the input box, to achieve the effect of fast input data.
Today we are here to achieve this effect.
First use the first layout to implement the interface
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " android:gravity= "Center_horizontal" tools:context= ". Mainactivity "> <edittext android:gravity=" center_horizontal " android:id=" @+id/tv_msg " Android:layout_width= "250DP" android:layout_height= "wrap_content" android:hint= "click right Quick Select"/> <imageview android:clickable= "true" android:layout_margintop= "10DP" android:layout_ alignright= "@id/tv_msg" android:id= "@+id/iv_down_arrow" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:src= "@drawable/down_arrow"/></relativelayout>
Use the layout to Listview,listview
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical " > <linearlayout android:layout_marginbottom= "5DP" android:gravity= "Center_vertical" Android: Layout_width= "Match_parent" android:layout_height= "wrap_content" android:orientation= "Horizontal" > <imageview android:id= "@+id/iv_user" android:layout_width= "Wrap_content" Android:lay out_height= "Wrap_content" android:src= "@drawable/user"/> <textview android:id= "@+id/tv _msg "android:gravity=" Center_horizontal "android:layout_width=" 0DP "Android:layout_heigh t= "Wrap_content" android:layout_weight= "1" android:text= "000000000"/> <imageview Android:id= "@+id/iv_delete" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:src= "@dra Wable/delete "/> </LinearLayout></LinearLayout>
<span style= "FONT-SIZE:18PX;" >package comflyou.down.select;import java.util.arraylist;import Android.app.activity;import android.os.Bundle; Import Android.renderscript.type.cubemapface;import Android.view.view;import Android.view.View.OnClickListener; Import Android.view.viewgroup;import Android.widget.baseadapter;import Android.widget.edittext;import Android.widget.imageview;import Android.widget.listview;import Android.widget.popupwindow;import Android.widget.textview;public class Mainactivity extends Activity {private EditText msg; Private ImageView image; Private Popupwindow Popupwindow; Private arraylist<string> dataList; Private ListView Mylistview; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); msg = (EditText) Findviewbyid (r.id.tv_msg); Image = (ImageView) Findviewbyid (R.id.iv_down_arrow); Mylistview = new ListView (mainactivity.this); Popupwindow = new Popupwindow (Getapplicationcontext ()); Fill data dataList = new arraylist<string> (); for (int i = 0; i <; i++) {Datalist.add ("flyou" + i); }//Initialize data init (); Initialize Lictview Initlistview (); } private void Init () {Image.setonclicklistener (new Onclicklistener () {@Override public void OnClick (View V) {//Set Popupwindow width popupwindow.setwidth (msg.getwidth ()); Set the height of the Popupwindow popupwindow.setheight (300); Popupwindow.setcontentview (Mylistview); Popupwindow.setoutsidetouchable (TRUE); Popupwindow.showasdropdown (msg, 0, 0); } }); } private void Initlistview () {mylistview.setbackgroundresource (r.drawable.listview_background);//Setting ListView Background mylistview.setdivider (NULL); Sets the separator line between entries to null mylistview.setverticalscrollbarenabled (FALSE); Close Mylistview.setadapter (new Myadapter ()); } public CLASS Myadapter extends Baseadapter {@Override public int getcount () {return datalist.size (); } @Override public Object getItem (int position) {return position; } @Override public long getitemid (int position) {return 0; } @Override Public View getView (final int position, View Convertview, ViewGroup parent) {Viewholder holder; if (Convertview = = null) {Convertview = View.inflate (Getapplicationcontext (), r.layout.list_item, NULL); Holder = new Viewholder (); Holder.iv_delete = (ImageView) Convertview.findviewbyid (r.id.iv_delete); Holder.iv_user = (ImageView) Convertview.findviewbyid (R.id.iv_user); Holder.tv_msg= (TextView) Convertview.findviewbyid (r.id.tv_msg); Convertview.settag (holder); } else {holder = (Viewholder) convertview.gettag (); } holder.tv_msg.setText (Datalist.get (position)); Holder.iv_delete.setOnClickListener (New Onclicklistener () {@OverRide public void OnClick (View v) {//Remove data datalist.remove (position); Update ListView MyAdapter.this.notifyDataSetChanged (); } }); Convertview.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {msg. SetText (Datalist.get (position)); Popupwindow.dismiss (); } }); return convertview; }}//data cache private class Viewholder {ImageView iv_delete; TextView tv_msg; ImageView Iv_user; }}</span>
Custom components drop-down quick Select components