当前位置: 首页 > news >正文

网页一键建站北京建设职工大学网站

网页一键建站,北京建设职工大学网站,阿里云域名解析,网站备案可以国际域名第四次作业-宝宝相册 题目 用Listview建立宝宝相册,相册内容及图片可自行设定,也可在资料文件中获取。给出模拟器仿真界面及代码截图。 (参考例4-8) 创建工程项目 创建名为baby的项目工程,最后的工程目录结构如下图所…

第四次作业-宝宝相册

题目

用Listview建立宝宝相册,相册内容及图片可自行设定,也可在资料文件中获取。给出模拟器仿真界面及代码截图。 (参考例4-8)

创建工程项目

创建名为baby的项目工程,最后的工程目录结构如下图所示:

image-20231027171437431

res/drawable文件中的i1、i2、i3、i4、i5、i6均为图片,即宝宝相册图片,网上自行选取照片即可。

res/layout为文件布局文件,activity_main.xml为自动生成的自定义布局文件,list_item.xml为自定义布局文件

布局文件

  1. 创建自定义布局文件list_item.xml文件

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"><ImageViewandroid:id="@+id/news_thumb"android:layout_width="100dp"android:layout_height="100dp"android:layout_margin="5dp"/><LinearLayoutandroid:orientation="vertical"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="5dp"><TextViewandroid:id="@+id/news_title"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="16sp" /><TextViewandroid:id="@+id/news_info"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="14sp"android:layout_marginTop="5dp"/></LinearLayout></LinearLayout>
    
  2. 修改MainActivity.xml布局文件

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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"android:paddingLeft="16dp"android:paddingRight="16dp"><ListViewandroid:id="@+id/list"android:layout_width="match_parent"android:layout_height="match_parent"/></RelativeLayout>
    

MainActivity文件

package com.example.baby;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;public class MainActivity extends AppCompatActivity {private ListView listView;private SimpleAdapter adapter;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 假设有一个包含数据的ListList<Map<String, String>> data = new ArrayList<>();Map<String, String> item1 = new HashMap<>();item1.put("news_thumb", String.valueOf(R.drawable.i1));	//R.drawable.i1引用照片资源文件item1.put("news_title", "毡帽系列");item1.put("news_info", "此系列服装有点cute,像不像小车夫。");data.add(item1);Map<String, String> item2 = new HashMap<>();item2.put("news_thumb", String.valueOf(R.drawable.i2));	//R.drawable.i2引用照片资源文件item2.put("news_title", "蜗牛系列");item2.put("news_info", "宝宝变成了小蜗牛,爬啊爬啊爬啊。");data.add(item2);Map<String, String> item3 = new HashMap<>();item3.put("news_thumb", String.valueOf(R.drawable.i3));item3.put("news_title", "小蜜蜂系列");item3.put("news_info", "小蜜蜂,嗡嗡嗡,飞到西,飞到东。");data.add(item3);Map<String, String> item4 = new HashMap<>();item4.put("news_thumb", String.valueOf(R.drawable.i4));item4.put("news_title", "毡帽系列");item4.put("news_info", "此系列服装有点cute,像不像小车夫。");data.add(item4);Map<String, String> item5 = new HashMap<>();item5.put("news_thumb", String.valueOf(R.drawable.i5));item5.put("news_title", "蜗牛系列");item5.put("news_info", "宝宝变成了小蜗牛,爬啊爬啊爬啊。");data.add(item5);Map<String, String> item6 = new HashMap<>();item6.put("news_thumb", String.valueOf(R.drawable.i6));item6.put("news_title", "小蜜蜂系列");item6.put("news_info", "小蜜蜂,嗡嗡嗡,飞到西,飞到东。");data.add(item6);// 定义数据的键与布局文件中组件的映射String[] from = {"news_thumb", "news_title", "news_info"};int[] to = {R.id.news_thumb, R.id.news_title, R.id.news_info};// 创建SimpleAdapteradapter = new SimpleAdapter(this, data, R.layout.list_item, from, to);// 关联SimpleAdapter与ListViewlistView = findViewById(R.id.list);listView.setAdapter(adapter);// 为ListView添加一个项目点击监听器,当点击项目时显示对话框listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position, long id) {// 获取点击项目的数据Map<String, String> itemData = (Map<String, String>) parent.getItemAtPosition(position);// 从点击项目的数据中提取文本信息以供对话框使用String title = itemData.get("news_title");String info = itemData.get("news_info");// 创建并显示一个自定义对话框AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);builder.setTitle(title).setMessage(info).setPositiveButton("确定", null); // 没有操作的确定按钮AlertDialog dialog = builder.create();dialog.show();}});}
}

修改AndroidManifest.xml文件

<activityandroid:name=".MainActivity"android:exported="true"android:label="SimpleAdapterDemo">		<!--修改导航栏名称--><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter>
</activity>

效果展示

http://www.yayakq.cn/news/111257/

相关文章:

  • 手机wap建站网站建设cms系统
  • 网站的关键词多少合适微信自己怎么做小程序
  • 网站的三大因素wordpress微信分享没有缩略图
  • 比较好的公文写作网站网络营销模式的优势
  • 什么是网站可信认证wordpress如何上传pdf
  • 做民宿的网站广州网站建设建航科技
  • 食品电子商务网站建设方案网站自己做
  • 图片素材网站哪个最多凯里小程序开发公司
  • 创意礼品做的比较好的网站企业网站域名服务器
  • 苏州建设公司网站建设wordpress邮件验证评论
  • 汽车之家网站做的很烂建设银行官网首页网站招聘
  • 揭阳网站如何制作网站后台打打开空白
  • 网站制作技术使用说明删除wordpress版权
  • 重庆网站建设制作设计代理国外网站
  • 南宁seo外包平台济南网站seo优化
  • 建设部网站官网造价工程师孙思新网站如何做营销
  • 建立门户网站的意义WordPress怎么设置2个菜单
  • 广东商城网站建设报价广告平台推广渠道
  • 山东省住房和城乡建设厅网站电话海阔天空网站建设
  • 济宁建设企业网站建设企业网站官方登录
  • 网站开发可行性分析报告洛阳网站建设哪个好点
  • 关键词搜索站长工具最新国内新闻10条
  • 比价网站 源码phpcms网站
  • 郑州网站推广多少钱郑州seo公司哪家好
  • 华北理工大学学科建设处网站永久免费域名注册
  • 手机网站免费建设排行网络编程技术试题
  • 邵阳建设网站的公司wordpress评论提醒
  • 网站seo搜索引擎优化怎么做写微信公众号用什么软件
  • 装修网站怎么建设免费的ppt模板软件
  • 长春火车站属于哪个区温州网站优化案例