自定义Spinner---利用TextView以及Dialog组合

MainActivity:

创新互联长期为超过千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为民勤企业提供专业的网站设计制作、网站设计,民勤网站改版等技术服务。拥有十年丰富建站经验和众多成功案例,为您定制开发。

package com.example.myspinner_bytextview;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @author 鹭岛猥琐男
 *
 */
public class MainActivity extends Activity
{

    private TextView tv_show;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        View sex = findViewById(R.id.sex);
        tv_show = (TextView) findViewById(R.id.tv_show);
        sex.setOnClickListener(new OnClickListener()
        {
           
            @Override
            public void onClick(View v)
            {
                AlertDialog.Builder builder;
                final AlertDialog dialog;
                View view = getLayoutInflater().inflate(R.layout.myspinner, null);
                builder=new AlertDialog.Builder(MainActivity.this);
                dialog=builder.create();
                dialog.setView(view, 0, 0, 0, 0);
                dialog.show();
                View sex_man = view.findViewById(R.id.sex_man);
                View woman = view.findViewById(R.id.woman);
                View shemale = view.findViewById(R.id.shemale);
                sex_man.setOnClickListener(new OnClickListener()
                {
                   
                    @Override
                    public void onClick(View v)
                    {
                        tv_show.setText("男性");
                        Toast.makeText(MainActivity.this, "性别:男性", Toast.LENGTH_LONG).show();
                        dialog.dismiss();
                       
                    }
                });
               
                woman.setOnClickListener(new OnClickListener()
                {
                   
                    @Override
                    public void onClick(View v)
                    {
                        tv_show.setText("女性");
                        Toast.makeText(MainActivity.this, "性别:男性", Toast.LENGTH_LONG).show();
                        dialog.dismiss();
                       
                    }
                });
               
                shemale.setOnClickListener(new OnClickListener()
                {
                   
                    @Override
                    public void onClick(View v)
                    {
                        tv_show.setText("人妖");
                        Toast.makeText(MainActivity.this, "性别:男性", Toast.LENGTH_LONG).show();
                        dialog.dismiss();
                       
                    }
                });
               
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

activity_main.xml

    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

            android:id="@+id/sex"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/sex_selector"
        android:layout_marginTop="60dp" >

                    android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="30dp"
            android:text="性别"
            android:textSize="20sp"
            android:textAppearance="?android:attr/textAppearanceMedium" />

                    android:id="@+id/tv_show"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:text="男性"
             android:textSize="20sp"
             android:textColor="#646464"
            android:layout_toLeftOf="@+id/p_w_picpathView1"
            android:layout_centerVertical="true"
            android:textAppearance="?android:attr/textAppearanceMedium" />

                    android:id="@+id/p_w_picpathView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="30dp"
            android:contentDescription="@string/app_name"
            android:src="@drawable/mydown" />

   

            android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/sex"
        android:background="#dcdcdc"
        android:textAppearance="?android:attr/textAppearanceMedium" />

            android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/sex"
        android:layout_centerHorizontal="true"
        android:background="#dcdcdc"
        android:textAppearance="?android:attr/textAppearanceMedium" />

mydialog.xml:


    android:layout_width="match_parent"
    android:layout_height="match_parent" >

            android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="#dcdcdc" />

            android:id="@+id/sex_man"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_below="@+id/textView1"
         android:background="@drawable/sex_selector"
        android:layout_centerHorizontal="true" >

                    android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="男性"
            android:textSize="20sp"
          
            android:textAppearance="?android:attr/textAppearanceMedium" />

   

            android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/sex_man"
        android:background="#dcdcdc"
        android:layout_centerHorizontal="true"
         />

            android:id="@+id/woman"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_below="@+id/textView3"
         android:background="@drawable/sex_selector"
        android:layout_centerHorizontal="true" >

                    android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="女性"
            android:textSize="20sp"
            android:textAppearance="?android:attr/textAppearanceMedium" />

   

            android:id="@+id/textView5"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/woman"
        android:layout_centerHorizontal="true"
        android:background="#dcdcdc"
         />

            android:id="@+id/shemale"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_below="@+id/textView5"
        android:background="@drawable/sex_selector"
        android:layout_centerHorizontal="true" >

                    android:id="@+id/textView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="人妖"
            android:textSize="20sp"
            android:textAppearance="?android:attr/textAppearanceMedium" />

   

            android:id="@+id/textView7"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#dcdcdc"
        android:layout_below="@+id/shemale"
        android:layout_centerHorizontal="true"
         />

自定义Spinner---利用TextView以及Dialog组合

自定义Spinner---利用TextView以及Dialog组合

自定义Spinner---利用TextView以及Dialog组合

DownLoad:http://download.csdn.net/detail/zzw0221/7530723


文章名称:自定义Spinner---利用TextView以及Dialog组合
本文网址:http://pwwzsj.com/article/jssjji.html