package com.example.eignth;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private Myadapter myadapter;
private ListView list_it;
private List<JsonBean.NewslistBean> newslist = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list_it = (ListView) findViewById(R.id.list_item);
MyTask myTask=new MyTask(new HttpCallback() {
@Override
public void callBack(String jsonstr) {
//解析json串
Gson gson = new Gson();
JsonBean jsot = gson.fromJson(jsonstr, JsonBean.class);
newslist = jsot.getNewslist();
setAdapter();
}
});
myTask.execute("https://api.tianapi.com/wxnew/?key=8d6e3228d25298f13af4fc40ce6c9679&num=10&page=1");
}
/**
* 设备适配器
*/
private void setAdapter(){
if(myadapter==null){
myadapter = new Myadapter(this,newslist);
list_it.setAdapter(myadapter);
}else{
myadapter.notifyDataSetChanged();
}
}
}
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private Myadapter myadapter;
private ListView list_it;
private List<JsonBean.NewslistBean> newslist = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list_it = (ListView) findViewById(R.id.list_item);
MyTask myTask=new MyTask(new HttpCallback() {
@Override
public void callBack(String jsonstr) {
//解析json串
Gson gson = new Gson();
JsonBean jsot = gson.fromJson(jsonstr, JsonBean.class);
newslist = jsot.getNewslist();
setAdapter();
}
});
myTask.execute("https://api.tianapi.com/wxnew/?key=8d6e3228d25298f13af4fc40ce6c9679&num=10&page=1");
}
/**
* 设备适配器
*/
private void setAdapter(){
if(myadapter==null){
myadapter = new Myadapter(this,newslist);
list_it.setAdapter(myadapter);
}else{
myadapter.notifyDataSetChanged();
}
}
}