Select a component from the "custom components" drop-down list and click the "custom components" drop-down list.

Source: Internet
Author: User

Select a component from the "custom components" drop-down list and click the "custom components" drop-down list.
Select components from the drop-down list

I believe that you have used QQ's recent logon drop-down box to display the effect of recent logon. You can click the option to submit the content to the input box to quickly enter data.

We will achieve this effect today.


First, use the first interface for layout implementation

<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 quick select on the right"/> <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 listview and listview Layout

<?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:layout_height="wrap_content"            android:src="@drawable/user" />        <TextView            android:id="@+id/tv_msg"            android:gravity="center_horizontal"            android:layout_width="0dp"            android:layout_height="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="@drawable/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 <20; 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 the PopupWindow width to popupWindow. setWidth (msg. getWidth (); // set the height of PopupWindow. set height (300); popupWindow. setContentView (myListview); popupWindow. setOutsideTouchable (true); popupWindow. showAsDropDown (msg, 0, 0) ;}});} private void initListView () {myListview. setBackgroundResource (R. drawable. listview_background); // sets the listView // background myListview. setDivider (null); // set the separation line between entries to null myListview. setVerticalScrollBarEnabled (false); // disable 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. yydatasetchanged () ;}}); 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>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.