最近在做一个关于ListView和网络请求的一个小demo,话不多说,上马,第一次写博客,不足之处望大家见谅。
MainActivity.java
public class MainActivity extends AppCompatActivity {
private String[] data ={};
private MyHandler handler;
ListView listView;
private MyAdapter adapter;
ArrayList<IconTextBean.bean> list = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
handler = new MyHandler();
listView = findViewById(R.id.showListView);
adapter = new MyAdapter(this,list);
listView.setAdapter(adapter);
//网络请求数据,通过Java Bean进行处理
getNetworkData();
}
//从网络得到的数据进行解析,
class MyHandler extends Handler{
@Override
public void handleMessage(Message msg) {
String s = (String)msg.obj;