How to make a ListView like in VK?

To flip through everything. Here is my code

public class News extends Fragment{ View view; int offset=0, count=10; ProgressDialog progressDialog; LayoutInflater layoutInflater; BaseAdapter baseAdapter; NewsGSON newsGSON; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view=inflater.inflate(R.layout.frag2,container,false); progressDialog=new ProgressDialog(getActivity()); progressDialog.setTitle("Загрузка данных"); progressDialog.show(); VKRequest vkRequest = new VKApiWall().get(VKParameters.from( VKApiConst.OWNER_ID,"-21314891", VKApiConst.COUNT,count, "filter","owner", VKApiConst.EXTENDED,1, VKApiConst.OFFSET,offset)); vkRequest.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { super.onComplete(response); newsGSON=new Gson().fromJson(response.responseString,NewsGSON.class); new Async().execute(); } @Override public void onError(VKError error) { super.onError(error); Log.e("response vkRequest = ", "error"); } }); return view; } class Async extends AsyncTask{ @Override protected Object doInBackground(Object[] params) { layoutInflater=LayoutInflater.from(getActivity()); baseAdapter=new BaseAdapter() { @Override public int getCount() { return count; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { convertView=layoutInflater.inflate(R.layout.frag2_adap,parent,false); TextView text1= (TextView) convertView.findViewById(R.id.text1); TextView text2= (TextView) convertView.findViewById(R.id.text2); TextView title= (TextView) convertView.findViewById(R.id.title); ImageView imageAva= (ImageView) convertView.findViewById(R.id.image_ava); ImageView image= (ImageView) convertView.findViewById(R.id.image); ImageView imageLike= (ImageView) convertView.findViewById(R.id.image_like); ImageView imageComment= (ImageView) convertView.findViewById(R.id.image_comment); TextView textLike= (TextView) convertView.findViewById(R.id.text_like); TextView textComment= (TextView) convertView.findViewById(R.id.text_comment); text1.setText(newsGSON.getResponse().getGroups().get(0).getName()); Date date = new Date( newsGSON.getResponse().getItems().get(position).getDate()*1000L ); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); sdf.setTimeZone( TimeZone.getTimeZone( "GMT+5" ) ); String d = sdf.format( date ); text2.setText(d); title.setText(newsGSON.getResponse().getItems().get(position).getText()); textLike.setText(String.valueOf(newsGSON.getResponse().getItems().get(position).getLikes().getCount())); textComment.setText(String.valueOf(newsGSON.getResponse().getItems().get(position).getComments().getCount())); Picasso.with(getActivity()) .load(newsGSON.getResponse().getItems().get(position).getAttachments().get(0).getPhoto().getPhoto_604()) .resize(300,300) .into(image); Picasso.with(getActivity()) .load(newsGSON.getResponse().getGroups().get(0).getPhoto_100()) .resize(70,70) .into(imageAva); if (position==10) { offset=3; } return convertView; } }; return null; } @Override protected void onPostExecute(Object o) { super.onPostExecute(o); ListView listView= (ListView) view.findViewById(R.id.listView); listView.setAdapter(baseAdapter); progressDialog.dismiss(); } } 

}

I don’t know how to do that if the scrolling position is> 10. That AsyncTask started again. To get the remaining 10 elements with an offset of 10.

How to do not know. The brain is cracking already

Can it be better to swing some thread?

0