Skip to content

Commit

Permalink
hzuapps#2 hzuapps#63 第二次实验
Browse files Browse the repository at this point in the history
  • Loading branch information
Jadore147258369 committed Oct 6, 2020
1 parent a6e5e1d commit 7137be6
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
19 changes: 19 additions & 0 deletions students/sec1814080911128/1814080911128JsonParse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package edu.hzuapps.androidlabs.sec1814080911128;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.List;

public class JsonParse {
public static List<NewsInfo>getNewsInfo(String json) {
//使用gson库解析json数据
Gson gson = new Gson();
//创建一个TypeToken的匿名子类对象,并调用对象的getType()方法
Type listType = new TypeToken<List<NewsInfo>>(){
}.getType();
//把获取到的信息集合存到newsInfo中
List<NewsInfo> newsInfos = gson.fromJson(json,listType);
return newsInfos;
}
}
46 changes: 46 additions & 0 deletions students/sec1814080911128/1814080911128MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package edu.hzuapps.androidlabs.sec1814080911128;

import android.os.Bundle;
import android.widget.LinearLayout;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private LinearLayout loading;
private ListView lvNews;
private List<NewsInfos>

@Override
protected void onCreate(Budle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
fillData();
}
//初始化控件
private void initView() {
loading = (L)
}

private void fillData() { }
//ListView适配器
private class NewsAdapter extends BaseAdapter {
//listview的item数
@Override
public int getCount() {
return newsInfos.size();
}

//条目对象
@Override
public Object getItem(int position) {
return null;
}

//条目id
@Override
public long getItemId(int position) {
return 0;
}
}
}
58 changes: 58 additions & 0 deletions students/sec1814080911128/1814080911128NewsInfoActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package edu.hzuapps.androidlabs.sec1814080911128;

public class NewInfoActivity {

private String icon; //图片路径
private String title; //新闻标题
private String content; //新闻描述
private String type; //新闻类型
private long comment; //新闻评论数

public NewInfoActivity(String icon, String title, String content, String type, long comment) {
this.icon = icon;
this.title = title;
this.content = content;
this.type = type;
this.comment = comment;
}

public String getIcon() {
return icon;
}

public void setIcon(String icon) {
this.icon = icon;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public long getComment() {
return comment;
}

public void setComment(long comment) {
this.comment = comment;
}
}

0 comments on commit 7137be6

Please sign in to comment.