Android作业0930
1.使用ListView和Adapter实现购物商城
Android 布局文件
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"> <ImageView
android:id="@+id/iv"
android:layout_width="170dp"
android:layout_height="150dp"
> </ImageView> <TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="50dp"
android:text="111"> </TextView> <TextView
android:id="@+id/tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:layout_marginLeft="-75dp"
android:text="222"> </TextView> </LinearLayout>
java类(三个)
package com.example.myhomework3; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;
import android.widget.ListView; import java.util.ArrayList;
import java.util.List; public class MainActivity extends AppCompatActivity { private List<shopping> shoppingList = new ArrayList<shopping>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initShopping();
shoppingAdapter shoppingAdapter = new shoppingAdapter(MainActivity.this,R.layout.item,shoppingList);
ListView listView = findViewById(R.id.lv1);
listView.setAdapter(shoppingAdapter);
} private void initShopping(){
shopping book = new shopping("限定","价格:500元",R.drawable.book);
shoppingList.add(book); shopping book1 = new shopping("书1","价格:26元",R.drawable.book1);
shoppingList.add(book1); shopping book2 = new shopping("书2","价格:29元",R.drawable.book2);
shoppingList.add(book2); shopping book3 = new shopping("书3","价格:36元",R.drawable.book3);
shoppingList.add(book3); shopping book4 = new shopping("书4","价格:18元",R.drawable.book4);
shoppingList.add(book4); shopping book5 = new shopping("书5","价格:33元",R.drawable.book5);
shoppingList.add(book5); shopping book6 = new shopping("书6","价格:52元",R.drawable.book6);
shoppingList.add(book6);
}
}
package com.example.myhomework3; import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView; import java.util.List; public class shoppingAdapter extends ArrayAdapter {
private final int resourceId; public shoppingAdapter(Context context, int textViewResourceId, List<shopping> objects){
super(context,textViewResourceId,objects);
resourceId = textViewResourceId;
} @Override
public View getView(int position, View convertView, ViewGroup viewGroup){
shopping shopping = (com.example.myhomework3.shopping)getItem(position);
View view = LayoutInflater.from(getContext()).inflate(resourceId,null);
ImageView imageView = view.findViewById(R.id.iv);
TextView textView1 = view.findViewById(R.id.tv1);
TextView textView2 = view.findViewById(R.id.tv2);
imageView.setImageResource(shopping.getImageId());
textView1.setText(shopping.getName());
textView2.setText(shopping.getPrice());
return view;
}
package com.example.myhomework3;
public class shopping {
private String name;
private String price;
private int imageId;
public shopping(String name, String price, int imageId) {
this.name = name;
this.price = price;
this.imageId = imageId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public int getImageId() {
return imageId;
}
public void setImageId(int imageId) {
this.imageId = imageId;
}
}


Android作业0930的更多相关文章
- Android作业分组与选题
期末大作业 序号 题目 组员分工 完成度 1 基于安卓系统的游戏开发 2 设计一个安卓手机小游戏 3 Android平台应用——音乐播放器设计 4 基于Android技术的个人博客 5 电子阅读器 6 ...
- 简单计算器 安卓 Android 作业
Android老师布置的课程作业——简单计算器 功能要求实现四则运算,参考界面见下图: 首先给各位老铁提供apk安装包以及项目压缩包,略表诚意~ github地址:https://github.com ...
- Android作业list
作业1. 请在自己的电脑上完成Android的安装与配置,并完成Hello Android项目.上交自己与项目的合照,将照片传至QQ群中. ------------------------------ ...
- Android作业
一.设置跑马灯功能 使用滚动字幕显示标题“请选择你喜欢哪种花” <?xml version="1.0" encoding="utf-8"?>&l ...
- Android作业 0923
计算器小应用 package com.example.myhomework2; import androidx.appcompat.app.AppCompatActivity; import andr ...
- Android作业10/07
1.多个Activity界面实现数据的传递 <?xml version="1.0" encoding="utf-8"?> <androidx. ...
- 错误提示”void is an invalid type for the variable“
今晚做android作业,出现错误提示:void is an invalid type for the variable, invalid:无效的 variable:变量,在网上找了一下后知道是 方 ...
- Android——手机内部文件存储(作业)
作业:把用户的注册信息存储到文件里,登录成功后读出并显示出来 activity_practice2的layout文件: <?xml version="1.0" encodin ...
- Android——SharedPreferences存储(作业)
作业:制作一个登录界面,以SP方式存储用户名.用户下次登录时自动显示上次填写的用户名 layout文件: <?xml version="1.0" encoding=" ...
随机推荐
- Git的详细使用
关于Git的详细使用,下面博主的博客写的非常的详细! 可以参考一下. https://blog.csdn.net/qq_19835247/article/details/104620042 人生需要准 ...
- 数据处理 | pandas入门专题——离散化与one-hot
今天是pandas数据处理专题第7篇文章,可以点击上方专辑查看往期文章. 在上一篇文章当中我们介绍了对dataframe进行排序以及计算排名的一些方法,在今天的文章当中我们来了解一下dataframe ...
- 用python导入20个G的json数据到Mysql数据库
整体思路参考资料:https://blog.csdn.net/layman2016/article/details/79252499 作业:有一个16个G的跟疫情相关的json新闻大数据(articl ...
- Python爬虫实战点触验证码, 模拟登陆bilibili
爬虫思路如下: 利用自动化爬虫工具 Selenium 模拟点击输入等操作来进行登录 分析页面,获取点触验证码的点触图片,通过将图片发送给超级鹰打码平台识别后获取坐标信息 根据超级鹰返回的数据,模拟坐标 ...
- jsBridge
jsBridge https://www.dazhuanlan.com/2019/12/05/5de7eb50739df/ JSBridge的原理 https://juejin.im/post/5ab ...
- 【转】Android DrawingCache
转自:http://magiclen.org/android-drawingcache/ 日期: 2014 年 8 月 27 日 | 作者: Magic Len 開發Android的時候,在許多情況下 ...
- List集合对象去重及按属性去重的8种方法-java基础总结系列第六篇
最近在写一些关于java基础的文章,但是我又不想按照教科书的方式去写知识点的文章,因为意义不大.基础知识太多了,如何将这些知识归纳总结,总结出优缺点或者是使用场景才是对知识的升华.所以我更想把java ...
- java之5分钟插入千万条数据
虽说不一定5分钟就插入完毕,因为取决去所插入的字段,如果字段过多会稍微慢点,但不至于太慢.10分钟内基本能看到结果. 之前我尝试用多线程来实现数据插入(百万条数据),半个多小时才二十多万条数据. 线程 ...
- String源码浅析
如果问你,开发过程中用的最多的类是哪个?你可能回答是HashMap,一个原因就是HashMap的使用量的确很多,还有就是HashMap的内容在面试中经常被问起. 但是在开发过程中使用最多的类其实并不是 ...
- Javaweb中的请求路径的相关总结
重定向和转发相对路径和绝对路径问题 注意:转发和重定向的URLString前有加 / 为绝对路径 反之为相对路径 1.假设通过表单请求指定的Url资源 action="LoginServ ...