forked from hzuapps/android-labs-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6e5e1d
commit 7137be6
Showing
3 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
students/sec1814080911128/1814080911128NewsInfoActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |