安卓开发学习-Android Studio-13-表格视图、日历
目录
- GridView
- calendarView
- DatePicker
GridView
表格视图。
MainActivity.java
package com.example.gridview;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.Toast;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);/*** 表格布局*/
// 处理添加数据String[] title = new String[]{"aci","ban","bon","egg","fu","gift","light","tip"};int[] img = new int[]{R.drawable.acichole, R.drawable.banboo, R.drawable.bong, R.drawable.egg, R.drawable.fu, R.drawable.gift, R.drawable.light, R.drawable.tip};List<Map<String, Object>> list = new ArrayList<>();for (int i=0;i<title.length;i++){Map<String,Object> map = new HashMap<>();map.put("name", title[i]);map.put("img", img[i]);list.add(map);}GridView gridView = findViewById(R.id.gridView);SimpleAdapter simpleAdapter = new SimpleAdapter(MainActivity.this, list,R.layout.grid_item, new String[]{"img","name"}, new int[]{R.id.imageView, R.id.textView});gridView.setAdapter(simpleAdapter);gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position, long id) {Toast.makeText(MainActivity.this, title[position], Toast.LENGTH_SHORT).show();}});}
}
activity_main.xml
<?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"><GridViewandroid:numColumns="4"android:id="@+id/gridView"android:layout_width="match_parent"android:layout_height="match_parent" />
</LinearLayout>
grid_item.xml
<?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:orientation="vertical"android:layout_width="match_parent"android:gravity="center"android:layout_height="match_parent"><ImageViewandroid:id="@+id/imageView"android:layout_width="120px"android:layout_height="120px"tools:srcCompat="@tools:sample/avatars" /><TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="TextView" />
</LinearLayout>
效果图:
calendarView
mainactivity.java
/*** 日历部分*/CalendarView calendarView = findViewById(R.id.calendarView);Button button = findViewById(R.id.button);// 初始时间SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");time = format.format(calendarView.getDate());// 获取选中时间calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {@Overridepublic void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) {time = year+"年"+month+"月"+dayOfMonth+"日";}});button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Toast.makeText(MainActivity.this, time, Toast.LENGTH_SHORT).show();}});
activity_main.xml
<CalendarViewandroid:id="@+id/calendarView"android:layout_width="match_parent"android:layout_height="wrap_content" /><Buttonandroid:id="@+id/button"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="enter" />
效果图:
DatePicker
另一种日历控件,不过默认给出的可能没有,需要手动把代码敲上去。
与calendar的区别是在日历表上方增加了一个显示日期的视图。这里就不演示了。
安卓开发学习-Android Studio-13-表格视图、日历相关推荐
- 【安卓开发】android studio 学习入门篇
以下内容转载自:https://blog.csdn.net/myosotis5/article/details/79208707 (为防止链接失效,特备份文章内容,侵删) 开发第一应用 可以开发属于自 ...
- 适合新手看的安卓开发书android studio
第一行代码 Android 第2版 第二版 郭霖 手机app Android 安卓开发从入门到精通程序设计编程教程教材书籍 https://s.click.taobao.com/RkUcrzv 推荐 ...
- 如何使用安卓开发工具 Android Studio
返回主页 千古壹号 博客园分享技术,公众号分享代码之外的技能.微信公众号:千古壹号. 博客园首页新随笔联系订阅管理 随笔 - 156 文章 - 0 评论 - 589 第一次使用Android Stud ...
- 【安卓开发】安卓开发工具: android studio(AS)的安装,配置与汉化保姆级详细教程
android studio官方下载地址 点击进入官网 点击option 选择下载版本 我是windows 64位选了这个exe 右键,以管理员身份运行出现如下界面,无脑next next next ...
- 安装安卓开发工具-Android Studio
本文简介 搭建Android Studio安卓开发环境. 操作步骤 一.下载Android Studio 下载迅雷加速下载(网速快的,直接略过本步骤).预计耗时:1分钟 在浏览器或者迅雷中打开如下网址 ...
- Android开发学习——Android Studio配置SVN
一.基本配置 1. 下载这个,然后双击 安装,按下图这样选 然后 傻瓜式安装 2. 进入Android studio设置:Use Command Line Client 选择浏览到第1步你本地安装 T ...
- 安卓开发学习-Android Studio-12-adapter
这里写目录标题 arrayAdapter simpleAdapter 适配器,顾名思义就是把数据变成适合界面的形式.可以说适配器就是数据与界面的桥梁. arrayAdapter <ListVie ...
- android 界面组件,安卓开发学习周第三篇——Android中的UI组件
原标题:安卓开发学习周第三篇--Android中的UI组件 在Android APP中,所有的用户界面元素都是由View和ViewGroup的对象构成的.View是绘制在屏幕上的用户能与之交互的一个对 ...
- android创建布局文件,android学习——Android Studio下创建menu布局文件
一.问题: android studio项目中没有看到menu文件夹: 在android studio项目中想要添加menu布局文件,一开始我的做法是:直接在res文件夹右键选择xml文件来添加,如下 ...
最新文章
- linux中使用u盘和光驱的命令_Linux操作系统下挂载硬盘光驱和U盘的方法
- WebBrowser内核指定
- python可变序列_python序列中可变数据类型有什么
- missing legacy device support
- 数据结构与算法--二叉树实现原理
- redis 设置密码 和 redis.config文件
- 使用和执行SQL Server Integration Services包的方法
- long到number转换 ts_js如何将纯数字字符串转换为long型
- Emacs lisp函数调用defun(五)
- 监听listview item兼容于checkbox/textview/imageview
- 编程英语单词1.编程常用英语词汇大全
- Web前端开发技术实验与实践(第3版)储久良编著实训11
- 苹果亮度自动调节怎么关闭_Android 亮度自动调节是如何实现的?
- python模拟类蠕虫--蠕虫初探
- 小学信息技术 用计算机画画 教学目标,三年级下册信息技术教学计划4篇
- 4.通过Opencv采集摄像头视频数据
- 机器人路径规划_人工势场法
- 手把手教你申请lynda高级账号,长期免费使用 lynda.com
- 百度IFE2018任务--20-21天
- 个人职业规划(可供参考)
热门文章
- 【论文阅读】Causal Imitative Model for Autonomous Driving
- 蓝桥杯Web组备赛笔记5
- mkfs/mk2fs/fsck/e2fsck/tune2fs/blkid
- google原生动态图标方案
- 如何解决Google浏览器卸载后无法重新安装的问题
- 默认的microsoft edge浏览器内如何打开IE浏览器(各大银行网银登陆时需要)
- 蓝桥杯模块学习17——AT24C02存储器(深夜学习——单片机)
- 三折线弹塑性滞回模型matlab,形状记忆合金的一维连续超弹性滞回模型
- 惊爆!机器可以思考有意识了? 道翰天琼认知智能平台API接口为您揭秘。
- MIAC移动安全赛web writeup【不全】