Before change:
public class Classroom {
private int class_id;
private String class_name;
private List<User> mUserList;
private List<Integer> rsc_tag_id;
public int getClass_id() {
return class_id;
}
public void setClass_id(int class_id) {
this.class_id = class_id;
}
public String getClass_name() {
return class_name;
}
public void setClass_name(String class_name) {
this.class_name = class_name;
}
public List<User> getUserList() {
return mUserList;
}
public void setUserList(List<User> userList) {
mUserList = userList;
}
public List<Integer> getRsc_tag_id() {
return rsc_tag_id;
}
public void setRsc_tag_id(List<Integer> rsc_tag_id) {
this.rsc_tag_id = rsc_tag_id;
}
}
After Change:
public class Classroom {
private int class_id;
private String class_name;
public int getClass_id() {
return class_id;
}
public void setClass_id(int class_id) {
this.class_id = class_id;
}
public String getClass_name() {
return class_name;
}
public void setClass_name(String class_name) {
this.class_name = class_name;
}
}
Tips:such changes may lead to some errors in other files, try to fix them!
Questions:why does class Image
in Image.java
have contribution String image_url
?
In PlanetCategoryActivity.java
:
- Where does the images come from?From back end!
- How to check if the invoke(调用) is success? Maybe is known now.
- How to due with the exception if database goes wrong? Retry or other method.
try to fix the code into following style:
const static int TEST = 1;
private static List<Image> images = Null;
if (Test)
{
images = initData();
}
else
{
/*
* download images by tag
* input: tag_id
* output: list<Image>
*/
}
public void initData()
{
List<Image> images = Null;
Image image = new Image(...)
//you can use image from baidu as test image!
...
return images
}
Tips 1:Try to merge entity
into activity
and adapter
Tips 2:Implement Download Image from url for test
for reference:
public static Bitmap getBitmapFromUrl(final String url)
{
URL myFileUrl = null;
Bitmap bitmap = null;
try {
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection conn = (HttpURLConnection) myFileUrl
.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
Tips 3:How to get image url?
Step 1:find a image network:https://image.baidu.com
Step 2:search something like cats:https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1580973198457_R&pv=&ic=&nc=1&z=&hd=&latest=©right=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&sid=&word=%E7%8C%AB
Step 4:press F12
or FN + F12
to find the html
file of the website
Step 5:find <img id="..." ... src="..." ...>
in the html file
Step 6:double click src
to copy to url of the image:https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1581578052&di=cb4ccb9774c2128dc471fa78afb17dd1&imgtype=jpg&er=1&src=http%3A%2F%2Fn.sinaimg.cn%2Fsinacn15%2F275%2Fw640h435%2F20181010%2Fcaba-hkrzvkw4936632.jpg
Step 7:download the image into Bitmap
using the code above
Advance Tip:try to minimize the total effort of revising your code if the requirement changes from downloading image from url into decoding images from a String(Something related to objected oriented analysis and design~)