import android.os.Handler;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private String picurl="http://172.17.8.100/movieApi/movie/v1/findReleaseMovieList?count=10&page=1";
private ViewPager view_pager;
private List<String> list=new ArrayList<>();
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
if (msg.what == 0){
int currentItem = view_pager.getCurrentItem();
currentItem++;
view_pager.setCurrentItem(currentItem);
handler.sendEmptyMessageDelayed(0,2000);
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view_pager= findViewById(R.id.view_pager);
doHttp();
}
private void doHttp() {
new Helder().get(picurl).result(new Helder.Httplister() {
@Override
public void success(String data) {
Gson gson = new Gson();
Bean bean = gson.fromJson(data, Bean.class);
for (int i=0;i<bean.getResult().size();i++){
String image = bean.getResult().get(i).getImageUrl();
list.add(image);
}
Adapterr adapterr = new Adapterr(list, MainActivity.this);
view_pager.setAdapter(adapterr);
handler.sendEmptyMessageDelayed(0,2000);
}
});
}
}
网络请求数据的viewpager
最新推荐文章于 2021-05-26 07:56:24 发布