Android基础——高级UI组件:下拉框,列表,滚动条视图

Android基础——高级UI组件:下拉框,列表,滚动条视图,第1张

概述布局文件<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apkes/android"xmlns:app="http://schemas.android.com/apkes-auto"xmlns:tools="http://sch

布局文件

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    tools:context=".MainActivity"    androID:orIEntation="vertical"    >    <Spinner        androID:ID="@+ID/spinner"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:entrIEs="@array/ctype"        />    <ListVIEw        androID:ID="@+ID/ListVIEw"        androID:layout_wIDth="wrap_content"        androID:layout_height="370dp"        androID:entrIEs="@array/ctype" />    <horizontalscrollview        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content">        <linearLayout            androID:layout_wIDth="match_parent"                androID:layout_height="match_parent"                androID:orIEntation="vertical">            <TextVIEw                androID:layout_wIDth="match_parent"                androID:layout_height="match_parent"                androID:text="@string/content"                androID:textSize="50sp" />            <TextVIEw                androID:layout_wIDth="match_parent"                androID:layout_height="match_parent"                androID:text="@string/content"                androID:textSize="50sp" />        </linearLayout>    </horizontalscrollview></linearLayout>

 

java实现 视图-适配器-资源 

package com.example.myhighuiiiii;import androIDx.appcompat.app.AppCompatActivity;import androID.os.Bundle;import androID.Widget.ArrayAdapter;import androID.Widget.ListVIEw;import androID.Widget.Spinner;import androID.Widget.Toast;//通过适配器来实现public class MainActivity extends AppCompatActivity {    Spinner spinner = null;    ListVIEw ListVIEw = null;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        /*        * 下拉列表框实现        * */        String[] ctype = new String[]{                "全部","美术","音乐","体育"        };        ArrayAdapter<String> adapter = new ArrayAdapter<String>(                this,androID.R.layout.simple_spinner_item,ctype        );        //为适配器设置列表框下拉时的选项样式        adapter.setDropDownVIEwResource(androID.R.layout.simple_spinner_dropdown_item);        spinner = (Spinner) findVIEwByID(R.ID.spinner);        //将适配器和下拉列表框关联起来        spinner.setAdapter(adapter);        //获取下拉列表框的选中值        String string = spinner.getSelectedItem().toString();        Toast.makeText(this,string,Toast.LENGTH_SHORT);        /*        * 列表视图实现        * */        String[] cctype = new String[]{                "全部","图书","游戏","电视"        };        //创建一个适配器        ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(                this,androID.R.layout.simple_List_item_1,cctype        );        //将适配器和ListVIEw相关联       ListVIEw = (ListVIEw) findVIEwByID(R.ID.ListVIEw);       ListVIEw.setAdapter(adapter);    }}

 

总结

以上是内存溢出为你收集整理的Android基础——高级UI组件下拉框列表,滚动条视图全部内容,希望文章能够帮你解决Android基础——高级UI组件:下拉框,列表,滚动条视图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1068335.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存