ITeye博客

android 入门 Gallery

chengyu2099 · 2012-04-25 20:03 · Android · 移动开发 · Markdown

[code="java"] package com.zte.android.lesstion; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.AdapterView; import android.widget.Gallery; import android.widget.Toast; /** * @author rychenga * * 水平方向上显示一组图片,以便于浏览 */ public class Activity_012_Gallery extends Activity { private Gallery gallery ; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_012_gallery_layout); //init gallery gallery = (Gallery)findViewById(R.id.l012_gallery1); //设置适配器(datasource) Activity_012_ImageAdapter adapter = new Activity_012_ImageAdapter(Activity_012_Gallery.this); gallery.setAdapter(adapter); //显示被选中部分所处的位置,显示信息持续2秒 gallery.setOnItemSelectedListener(new OnItemSelectedListener() { //覆盖2个默认方法 public void onItemSelected(AdapterView parent, View view, int position, long id) { // TODO Auto-generated method stub Toast.makeText(Activity_012_Gallery.this, "第"+position+"张", 2).show(); } public void onNothingSelected(AdapterView arg0) { // TODO Auto-generated method stub } }); } } [/code] [code="xml"] [/code]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。