简单的电子书的android小项目,实现简单电子书的功能,电子书不可看,只是张图片加上简单的点击描述和长按删除功能
(一)、java文件
1、novel文件
package com.example.class6; public class Novel { String name; int imageId; String author; String infor1; public Novel(String name, int imageId, String author, String infor1){ this.name=name; this.imageId=imageId; this.author=author; this.infor1=infor1; } public Novel(String name, int imageId){ this.name=name; this.imageId=imageId; } public String getName(){ return name; } public int getImageId(){ return imageId; } public String getAuthor(){ return author; } public String getInfor1(){ return infor1; } }
2、novelAdapter文件
package com.example.class6; 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 androidx.annotation.NonNull; import java.util.List; public class NovelAdapter extends ArrayAdapter<Novel> { private int resourceId; public NovelAdapter(@NonNull Context context, int resource, @NonNull List<Novel> objects) { super(context, resource, objects); resourceId = resource; } @Override public View getView(int position, View convertView, ViewGroup parent) { Novel book = getItem(position); View view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);//动态加载当前子视图布局 ImageView bookimg = view.findViewById(R.id.book_img); TextView bookName = view.findViewById(R.id.book_name); TextView booAuthor = view.findViewById(R.id.book_author);