Pull Torefresh ListView
5949 ワード
アップデートしてローディングしたのは、リブラとgsonです。
MainActivity
MainActivityレイアウト
MainActivity
public class MainActivity extends AppCompatActivity {
String url="http://169.254.167.244:8080/Web_Data/GetPhones?pagesize=20&pageindex=";
int index=1;
private PullToRefreshListView lv;
List
アダプターpublic class MyAdapter extends BaseAdapter {
Context context;
List
非同期タスクローディングネットワークからデータをダウンロードするpublic class MyAsyncTask extends AsyncTask {
//Context context;
CallBack callBack;
public MyAsyncTask(CallBack callBack){
//this.context=context;
this.callBack=callBack;
}
@Override
protected String doInBackground(String... params) {
try {
URL url=new URL(params[0]);
HttpURLConnection huc=(HttpURLConnection) url.openConnection();
huc.setConnectTimeout(3000);
huc.connect();
if(huc.getResponseCode()==200){
InputStream inputStream = huc.getInputStream();
byte[] b=new byte[1024];
int len=0;
StringBuilder sb=new StringBuilder();
while ((len=inputStream.read(b))!=-1){
sb.append(new String(b,0,len));
}
return sb.toString();
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
callBack.sendResult(s);
}
interface CallBack{
void sendResult(String json);
}
}
実体類はしません。MainActivityレイアウト
リスト.アイテムレイアウト