android Spinner的简单demo(用到BaseAdapter)
来源:互联网 发布:windows资源管理器占用 编辑:程序博客网 时间:2024/06/08 17:44
package com.example.spinnerdemo;import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.Spinner;import android.widget.TextView;/** * Spinner 是 ViewGroup的间接子类 可以做容器 * */public class MainActivity extends Activity {private int[] mImages = { R.drawable.bomb5, R.drawable.bomb6,R.drawable.bomb7, R.drawable.bomb8, R.drawable.bomb9 };private String[] mText = { "疯狂的 Android 讲义", "疯狂的 Java 讲义","疯狂的 Python 讲义", "疯狂的 XML 讲义", "疯狂的 HTML 讲义", };@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Spinner spinner = (Spinner) findViewById(R.id.spinner);BaseAdapter baseAdapter = new BaseAdapter() {@Overridepublic int getCount() {return 5;}@Overridepublic Object getItem(int arg0) {return null;}@Overridepublic long getItemId(int arg0) {return 0;}@Overridepublic View getView(int pos, View arg1, ViewGroup arg2) {LinearLayout liner = new LinearLayout(MainActivity.this);liner.setOrientation(LinearLayout.HORIZONTAL);ImageView image = new ImageView(MainActivity.this);image.setImageResource(mImages[pos]);TextView textView = new TextView(MainActivity.this);textView.setText(mText[pos]);textView.setTextColor(Color.BLACK);liner.addView(image);liner.addView(textView);return liner;}};spinner.setAdapter(baseAdapter);}}
查了下getView:
getView
View getView(int position,
View convertView,
ViewGroup parent)
Get a View that displays the data at the specified position in the data set. You can either create a View manually or inflate it from an XML layout file. When the View is inflated, the parent View (GridView, ListView...) will apply default layout parameters unless you use LayoutInflater.inflate(int, android.view.ViewGroup, boolean) to specify a root view and to prevent attachment to the root.
参数:
position - The position of the item within the adapter's data set of the item whose view we want.
convertView - The old view to reuse, if possible. Note: You should check that this view is non-null and of an appropriate type before using. If it is not possible to convert this view to display the correct data, this method can create a new view.
parent - The parent that this view will eventually be attached to
返回:
A View corresponding to the data at the specified position.
实现效果:
- android Spinner的简单demo(用到BaseAdapter)
- Android Spinner的DEMO
- Android BaseAdapter(Spinner,ListView,GridView)的使用
- Android笔记 简单demo Spinner AutoCompleteTextView Menu
- Android中万能的BaseAdapter(Spinner,ListView,GridView)的使用!
- Android中万能的BaseAdapter(Spinner,ListView,GridView)的使用!
- Android 中万能的 BaseAdapter(Spinner,ListView,GridView) 的使用!
- Android中万能的BaseAdapter(Spinner,ListView,GridView)的使用!
- Android 中万能的 BaseAdapter(Spinner,ListView,GridView) 的使用!
- [Android]简单Spinner的用法
- android Spinner的简单使用
- Android 基本控件的使用七(ListView+BaseAdapter)(demo)
- Android高手进阶教程(十六)之---Android中万能的BaseAdapter(Spinner,ListView,GridView)的使用!
- Android高手进阶教程(十六)之---Android中万能的BaseAdapter(Spinner,ListView,GridView)的使用!
- Android高手进阶教程(十六)之---Android中万能的BaseAdapter(Spinner,ListView,GridView)的使用!
- Android高手进阶教程(十六)之---Android中万能的BaseAdapter(Spinner,ListView,GridView)的使用!
- Android高手进阶教程(十五)---Android中万能的BaseAdapter(Spinner,ListView,GridView)的使用!
- Android高手进阶教程(十六)之---Android中万能的BaseAdapter(Spinner,ListView,GridView)的使用!
- 直接插入排序
- LogBack简易教程
- C++中的构造函数与创建对象的(简单)过程
- Facebook Hacker Cup 2015 Round 1 --- Winning at Sports
- Scrum基础
- android Spinner的简单demo(用到BaseAdapter)
- 汇编指令
- Mono For Android 如何控制程序在自动旋转功能开启下不进行横竖屏切换
- Android跳转Activity
- 如何让type="checkbox"不选中啊
- 单点登录 Ucenter 分析
- 思科CCNA第二学期第一章答案
- 苏飞论坛
- 从域名获取IP地址