网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

自定义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://bjjierui.cn/article/jssjji.html

其他资讯