I have a GridView and adapter for GridView (BasketAdapter extends BaseAdapter).
I load data in GridView from sharedpref file.
After I change data, I resave sharedpref file with data and call notifyDataSetChanged().
But notifyDataSetChanged() doesn't work unfortunately.
If I create new adapter and set it to my GridView, it works.
Can anyone help me with this issue?
Here is my code:
public class FragmentBasket extends SherlockFragment {
// my gridview
GridView gvCatalogAllStoneBasket;
// list of data from shared pref
ArrayList<CatalogItem> catalogItemBasket = new ArrayList<CatalogItem>();
ActionMode mode;
public static CatalogItem catalogItem;
// id variables for actionmode's actions
static final int ID_DELETE = 1;
static final int ID_EDIT = 2;
// shared pref id string
static String SHARED_PREFS_FILE = "basket";
// my adapter
BasketAdapter adapter = null;
public FragmentBasket() {
}
#Override
public void onStart() {
super.onStart();
// loading saved data from file
new GetCatalogAllStoneBasket().execute();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Receiver receiver = new Receiver();
IntentFilter intentFilterAdd = new IntentFilter("com.example.myproject.ADD_ITEM_BASKET");
IntentFilter intentFilterEdit = new IntentFilter("com.example.myproject.EDIT_ITEM_BASKET");
IntentFilter intentFilterDelete = new IntentFilter("com.example.myproject.DELETE_ITEM_BASKET");
getActivity().registerReceiver(receiver, intentFilterAdd);
getActivity().registerReceiver(receiver, intentFilterEdit);
getActivity().registerReceiver(receiver, intentFilterDelete);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.right_panel_fragment_catalog_grid, container, false);
gvCatalogAllStoneBasket = (GridView)view.findViewById(R.id.gvCatalogAllStoneBasket);
gvCatalogAllStoneBasket.setOnItemLongClickListener(new OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
// start action mode and send id of clicked item
mode = getSherlockActivity().startActionMode(new ActionModeOfBasket(String.valueOf(view.getTag())));
return false;
}
});
return view;
}
private final class ActionModeOfBasket implements ActionMode.Callback
{
String itemId;
public ActionModeOfBasket(String itemId) {
// get id from clicked item
this.itemId = itemId;
}
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
menu.add(0, ID_EDIT, 0, "Edit")
.setIcon(android.R.drawable.ic_menu_edit)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
menu.add(0, ID_DELETE, 1, "Delete")
.setIcon(android.R.drawable.ic_menu_delete)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
return true;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// get file
SharedPreferences sPref = getActivity().getSharedPreferences(SHARED_PREFS_FILE, getActivity().MODE_PRIVATE);
// open file for reading, writing
BasketHelper bHelper = new BasketHelper(sPref, getActivity());
switch (item.getItemId())
{
// if clicked del button
case ID_DELETE:
// delete item
bHelper.DelItem(itemId);
mode.finish();
catalogItemBasket = bHelper.GetAllItems();
break;
// if clicked edit button
case ID_EDIT:
// edit item
bHelper.EditItem(itemId, getFragmentManager());
mode.finish();
catalogItemBasket = bHelper.GetAllItems();
break;
}
return true;
}
#Override
public void onDestroyActionMode(ActionMode mode) {
}
}
class GetCatalogAllStoneBasket extends AsyncTask<String, String, String>
{
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected String doInBackground(String... params) {
SharedPreferences sPref = getActivity().getSharedPreferences(FragmentCatalogStonePosition.SHARED_PREFS_FILE, getActivity().MODE_PRIVATE);
try {
if(sPref.getString(FragmentCatalogStonePosition.TASK, null) != null)
{
BasketHelper bHelper = new BasketHelper(sPref, getActivity());
catalogItemBasket = bHelper.GetAllItems();
}
} catch (Exception e) {
Log.d(MainActivity.tag, e.getMessage() + " " + e.getCause());
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
adapter = new BasketAdapter(getActivity(), catalogItemBasket);
gvCatalogAllStoneBasket.setAdapter(adapter);
}
}
class Receiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().toString() == "com.example.myproject.ADD_ITEM_BASKET")
{
}
else if(intent.getAction().toString() == "com.example.myproject.EDIT_ITEM_BASKET")
{
// this code doesn't work (((
adapter.notifyDataSetChanged();
// this one successfully works
BasketAdapter bAdapter = new BasketAdapter(getActivity(), catalogItemBasket);
gvCatalogAllStoneBasket.setAdapter(bAdapter);
}
else if(intent.getAction().toString() == "com.example.myproject.DELETE_ITEM_BASKET")
{
}
}
}
class BasketAdapter extends BaseAdapter
{
Context context = null;
ArrayList<CatalogItem> data = null;
public BasketAdapter(Context context, ArrayList<CatalogItem> data) {
this.context = context;
this.data = data;
}
#Override
public int getCount() {
return data.size();
}
public CatalogItem getItem(int position) {
return data.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if(view == null)
{
LayoutInflater inflater = getLayoutInflater(null);
view = inflater.inflate(R.layout.right_panel_fragment_catalog_grid_item, parent, false);
CatalogItem item = getItem(position);
((TextView)view.findViewById(R.id.tvCatalogItemBasketName)).setText(item.name + " / " + item.code);
Double gPrice = Double.valueOf(item.price) * Double.valueOf(item.count);
((TextView)view.findViewById(R.id.tvCatalogItemBasketCount)).setText(String.valueOf(item.count));
((TextView)view.findViewById(R.id.tvCatalogItemBasketGeneralPrice)).setText(String.valueOf(gPrice));
((TextView)view.findViewById(R.id.tvCatalogItemBasketDescription)).setText(item.description);
final ImageView imgView = (ImageView)view.findViewById(R.id.ivCatalogItemBasketImage);
String strURL = "http://myproject.ua/images/stock/" + item.folder + "/" + item.images + "_800x600.jpg";
ImageLoaderConfiguration config = ImageHelper.ImageConfig(getActivity().getApplicationContext());
DisplayImageOptions options = ImageHelper.ImageOptions();
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
final ProgressBar pImgDialog = (ProgressBar)view.findViewById(R.id.pbImage);
imageLoader.displayImage(strURL, imgView, options, new ImageLoadingListener() {
#Override
public void onLoadingStarted(String imageUri, View view) {
pImgDialog.setVisibility(View.VISIBLE);
imgView.setVisibility(View.GONE);
}
#Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
pImgDialog.setVisibility(View.GONE);
imgView.setVisibility(View.VISIBLE);
}
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
pImgDialog.setVisibility(View.GONE);
imgView.setVisibility(View.VISIBLE);
}
#Override
public void onLoadingCancelled(String imageUri, View view) {
pImgDialog.setVisibility(View.GONE);
imgView.setVisibility(View.VISIBLE);
}
});
view.setTag(item.catalog_id);
}
return view;
}
}
}
Your convertView isn't null in case the View is recycled, so your getView() should be something like this:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if(view == null)
{
LayoutInflater inflater = getLayoutInflater(null);
view = inflater.inflate(R.layout.right_panel_fragment_catalog_grid_item, parent, false);
}
CatalogItem item = getItem(position);
((TextView)view.findViewById(R.id.tvCatalogItemBasketName)).setText(item.name + " / " + item.code);
Double gPrice = Double.valueOf(item.price) * Double.valueOf(item.count);
((TextView)view.findViewById(R.id.tvCatalogItemBasketCount)).setText(String.valueOf(item.count));
((TextView)view.findViewById(R.id.tvCatalogItemBasketGeneralPrice)).setText(String.valueOf(gPrice));
((TextView)view.findViewById(R.id.tvCatalogItemBasketDescription)).setText(item.description);
final ImageView imgView = (ImageView)view.findViewById(R.id.ivCatalogItemBasketImage);
String strURL = "http://myproject.ua/images/stock/" + item.folder + "/" + item.images + "_800x600.jpg";
ImageLoaderConfiguration config = ImageHelper.ImageConfig(getActivity().getApplicationContext());
DisplayImageOptions options = ImageHelper.ImageOptions();
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
final ProgressBar pImgDialog = (ProgressBar)view.findViewById(R.id.pbImage);
imageLoader.displayImage(strURL, imgView, options, new ImageLoadingListener() {
#Override
public void onLoadingStarted(String imageUri, View view) {
pImgDialog.setVisibility(View.VISIBLE);
imgView.setVisibility(View.GONE);
}
#Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
pImgDialog.setVisibility(View.GONE);
imgView.setVisibility(View.VISIBLE);
}
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
pImgDialog.setVisibility(View.GONE);
imgView.setVisibility(View.VISIBLE);
}
#Override
public void onLoadingCancelled(String imageUri, View view) {
pImgDialog.setVisibility(View.GONE);
imgView.setVisibility(View.VISIBLE);
}
});
view.setTag(item.catalog_id);
return view;
}
and since you have your own ArrayList inside your adapter, you have to update this one as well. Just add this method to your BasketAdapter:
public void changeModelList(List<CatalogItem> models) {
this.data = models;
notifyDataSetChanged();
}
and use it instead of notifyDataSetChanged().
it's not tested, but i think this is your problem.
Related
I have worked with the concept of filter that have to filter the job from job list based on skills and some list or there.
https://postimg.org/image/g3p1z6lbd/ - DashBoard Fragment.
About DashBoardFragment:
Contains job list view.
Dash Filter Button. - which redirect to the Filter screen.
public class DashBoardRefactor extends Fragment {
public static ProgressDialog progress;
public static List<DashListModel> dashRowList1 = new ArrayList<DashListModel>();
public static View footerView;
// #Bind(R.id.dashListView)
public static ListView dashListView;
int preCount = 2, scroll_Inc = 10, lastCount;
boolean flag = true;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.dashboard_fragment, container, false);
ButterKnife.bind(this, v);
setHasOptionsMenu(true);
progress = new ProgressDialog(getActivity());
dashListView = (ListView) v.findViewById(R.id.dashListView);
footerView = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.dashboard_list_footer, null, false);
dashListView.addFooterView(footerView);
footerView.setVisibility(View.GONE);
dashRowList1.clear();
dashboardViewTask();
dashListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("onItemClick", "onItemClick <---- ");
Intent toPositionDetail = new Intent(getActivity(), PositionDetailScreenRefactor.class);
toPositionDetail.putExtra("id", dashRowList1.get(position).getDashId());
startActivity(toPositionDetail);
getActivity().overridePendingTransition(R.anim.trans_left_in, R.anim.trans_left_out);
}
});
final int totalJobCount = SessionStores.gettotalJobList(getActivity());
Log.e("totalJobCount", "totalJobCount----" + totalJobCount);
dashListView.setOnScrollListener(new EndlessScrollListener(getActivity(), dashListView, footerView));
return v;
}
public void dashboardViewTask() {
progress.setMessage("Please Wait. It is Loading..job orders....");
progress.setCanceledOnTouchOutside(false);
progress.setCancelable(false);
progress.show();
// footerView.setVisibility(View.VISIBLE);
Map<String, String> params = new HashMap<String, String>();
Log.e("candidate_id", "candidate_id---->" + SessionStores.getBullHornId(getActivity()));
params.put("candidate_id", SessionStores.getBullHornId(getActivity()));
params.put("page", "1");
new DashBoardTask(getActivity(), params, dashListView, footerView);
// progress.dismiss();
}
#Override
public void onCreateOptionsMenu(
Menu menu, MenuInflater inflater) {
if (menu != null) {
menu.removeItem(R.id.menu_notify);
}
inflater.inflate(R.menu.menu_options, menu);
MenuItem item = menu.findItem(R.id.menu_filter);
item.setVisible(true);
getActivity().invalidateOptionsMenu();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.his__menu_accept:
Toast.makeText(getActivity(), "clicked dashboard menu accept", Toast.LENGTH_LONG).show();
return true;
case R.id.menu_filter:
// click evnt for filter
Toast.makeText(getActivity(), "clicked dashboard filter", Toast.LENGTH_LONG).show();
Intent filter_intent = new Intent(getActivity(), DashBoardFilterScreen.class);
startActivity(filter_intent);
getActivity().overridePendingTransition(R.anim.trans_left_in, R.anim.trans_left_out);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void onPause() {
super.onPause();
// dashboardViewTask();
}}
DashBoardTask:
public class DashBoardTask {
public DashBoardTask(Context context, Map<String, String> params, ListView dashListView, View footerView) {
this.context = context;
Log.e("context ", "DashBoardTask: " + context);
this.dashListView = dashListView;
this.params = params;
this.footerView = footerView;
ResponseTask();
}
private void ResponseTask() {
new ServerResponse(ApiClass.getApiUrl(Constants.DASHBOARD_VIEW)).getJSONObjectfromURL(ServerResponse.RequestType.POST, params, authorizationKey, context, "", new VolleyResponseListener() {
#Override
public void onError(String message) {
if (DashBoardRefactor.progress.isShowing()) {
DashBoardRefactor.progress.dismiss();
}
}
#Override
public void onResponse(String response) {
//Getting Response and Assign into model Class
int currentPosition = dashListView.getFirstVisiblePosition();
dashListAdapter = new DashListAdapter(context, DashBoardRefactor.dashRowList1, dashListView);
dashListView.setAdapter(dashListAdapter);
((BaseAdapter) dashListAdapter).notifyDataSetChanged();
if (currentPosition != 0) {
// Setting new scroll position
dashListView.setSelectionFromTop(currentPosition + 1, 0);
}
if (footerView.isShown()) {
footerView.setVisibility(View.GONE);
}
//progress.dismiss();
if (DashBoardRefactor.progress.isShowing()) {
try {
DashBoardRefactor.progress.dismiss();
} catch (Exception e) {
e.printStackTrace();
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
}
DashListAdapter:
________________
public class DashListAdapter extends BaseAdapter {
public static ListView dashListView;
Context c;
private LayoutInflater inflater;
private List<DashListModel> dashRowList;
public DashListAdapter(Context c, List<DashListModel> dashRowList, ListView dashListView) {
this.c = c;
this.dashListView = dashListView;
this.dashRowList = dashRowList;
}
#Override
public int getCount() {
return this.dashRowList.size();
}
#Override
public Object getItem(int position) {
return dashRowList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder dashHolder;
if (inflater == null)
inflater = (LayoutInflater) c
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.dashboard_jobdetails_list, null);
Log.e("get pos", "get pooooossss---->" + dashRowList.get(position));
final DashListModel dashModel = dashRowList.get(position);
dashHolder = new ViewHolder(convertView);
//Assign the value into screen
dashHolder.dash_company_name.setText(dashModel.getDashCompanyName());
}
the above code for displaying dashboard fragment list.
https://postimg.org/image/nqvp1dud9/ - This link is FilterScreen
By using this image if i filter the job based on the designed UI detail. That should replace into the DashboadFragment list The result should display into the DashBoard Fragment. How can I add pagination on Filter screen the same which have in DashBoardFragment.
This is my fragment where I create the listview. When the data changed the listview is not notify. How can I do this? I make the request in viewModel using volley. I receive the next error: java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(2131558620, class android.widget.ListView) with Adapter(class pharma.com.pharmaapp.Common.EventsArrayAdapter)]
at android.widget.ListView.layoutChildren(ListView.java:1582)
public class EventesFragment extends Fragment {
private final String TAG = EventesFragment.class.getSimpleName();
private ArrayList<EvenimentType> events = new ArrayList<>();
private ListView eventsListView;
private SwipeRefreshLayout swipeContainer;
public EventsArrayAdapter eventsArrayAdapter;
private EventsFragmentViewModel eventsFragmentViewModel = new EventsFragmentViewModel();
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_events, container, false);
FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), SearchActivity.class);
startActivity(intent);
}
});
if(events.size() != 0) {
events.clear();
}
eventsListView = (ListView) view.findViewById(R.id.listView_events);
swipeContainer = (SwipeRefreshLayout) view.findViewById(R.id.swipeContainer);
eventsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String name = ((EvenimentType) eventsListView.getAdapter().getItem(position)).getName();
Log.d(TAG, "Click " + name);
Intent intent = new Intent(getActivity(), SelectedEventActivity.class);
intent.putExtra("Parceable", events.get(position));
startActivity(intent);
}
});
eventsListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
String name = ((EvenimentType) eventsListView.getAdapter().getItem(position)).getName();
return false;
}
});
swipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
events.clear();
eventsFragmentViewModel.loadEvents(getActivity());
eventsFragmentViewModel.setInterface(new EventsFragmentViewModel.EventsFragmentInterface() {
#Override
public void takeData(ArrayList<EvenimentType> list) {
if(eventsArrayAdapter == null) {
eventsArrayAdapter = new EventsArrayAdapter(getActivity(), list);
eventsListView.setAdapter(eventsArrayAdapter);
swipeContainer.setRefreshing(false);
} else {
events = list;
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
eventsArrayAdapter.notifyDataSetChanged();
}
});
swipeContainer.setRefreshing(false);
}
}
});
}
});
loadEvents();
return view;
}
public void loadElementsToArrayAdapter() {
eventsArrayAdapter = new EventsArrayAdapter(getContext(), events);
// eventsArrayAdapter.notifyDataSetChanged();
swipeContainer.setRefreshing(false);
eventsListView.setAdapter(eventsArrayAdapter);
eventsFragmentViewModel.saveEvents(events, getActivity());
}
public void loadEvents() {
eventsFragmentViewModel.loadEvents(getActivity());
eventsFragmentViewModel.setInterface(new EventsFragmentViewModel.EventsFragmentInterface() {
#Override
public void takeData(ArrayList<EvenimentType> list) {
events = list;
loadElementsToArrayAdapter();
}
});
}
#Override
public void onResume() {
super.onResume();
// eventsFragmentViewModel.getUserEventsId(getActivity());
}
}
This is the Base Adapter class:
public class EventsArrayAdapter extends BaseAdapter {
private static final String TAG = EventsArrayAdapter.class.getSimpleName();
private Context context;
private List<EvenimentType> list = null;
public EventsArrayAdapter(Context context, List<EvenimentType> objects) {
this.context = context;
this.list = objects;
}
public void addAll(List<EvenimentType> objects) {
if(list == null) {
list = new ArrayList<>();
}
list.addAll(objects);
notifyDataSetChanged();
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(convertView == null) {
convertView = inflater.inflate(R.layout.item_array_adapter, null);
}
TextView title = (TextView) convertView.findViewById(R.id.text_simposion_title);
TextView date = (TextView) convertView.findViewById(R.id.text_simposion_date);
TextView location = (TextView) convertView.findViewById(R.id.text_simposion_location);
TextView price = (TextView) convertView.findViewById(R.id.text_simposion_price);
ImageView image = (ImageView) convertView.findViewById(R.id.image_event);
Log.d(TAG, "Checking: " + checkEvent(list.get(position)));
if (checkSelection(list.get(position)) == true) {
title.setText(list.get(position).getName());
date.setText(list.get(position).getDate());
location.setText(list.get(position).getLocation());
price.setText(list.get(position).getPaid());
image.setImageResource(R.drawable.ic_simposions);
} else {
title.setText(list.get(position).getName());
date.setText(list.get(position).getDate());
location.setText(list.get(position).getLocation());
price.setText(list.get(position).getPaid());
}
Log.d(TAG, "getView");
return convertView;
}
This is the viewModel where I make the request
public class EventsFragmentViewModel extends LoginViewModel {
private static final String TAG = EventsFragmentViewModel.class.getSimpleName();
private ArrayList<EvenimentType> events = new ArrayList<>();
EventsFragmentInterface listener = null;
public void loadEvents(final Context context) {
DataServices dataServices = new DataServices(context);
dataServices.getEvents();
dataServices.setCommunicationInterface(new RequestToServer.CommunicationInterface() {
#Override
public void takeResponse(JSONObject response) {
try {
Log.d(TAG, response.toString());
EvenimentType evenimentType = new EvenimentType();
JSONArray obj = response.getJSONArray("entry");
Log.d(TAG, obj.length() + "");
for (int i = 0; i < obj.length(); i++) {
events.add(evenimentType.createEvent(obj.getJSONObject(i)));
}
} catch (JSONException e) {
e.printStackTrace();
}
Log.d(TAG, "EVENTS: " + events.size());
if(listener!= null) {
listener.takeData(events);
}
}
});
}
public void saveEvents(ArrayList<EvenimentType> list, Context context) {
Preferences preferences = new Preferences(context);
preferences.saveToSharedPreferencesEvents(list);
preferences.getFromSharedPreferencesEvents();
}
public void setInterface(EventsFragmentInterface listener) {
this.listener = listener;
}
public interface EventsFragmentInterface {
public void takeData(ArrayList<EvenimentType> list);
}
}
progress bar only on current item, not on others.
when i long clicking on item the progress bar shown on to or more items and changing position.
i want show progressbar only on clicked item not other items
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> av, View v, int pos, long id) {
String getidtoextra = ((TextView) v.findViewById(R.id.wallid)).getText().toString();
final ProgressBar itemprogress = (ProgressBar) v.findViewById(R.id.itemprogress);
itemprogress.setVisibility(View.VISIBLE);
DownloadManager manager = new DownloadManager();
String destPath = Environment.getExternalStorageDirectory() + File.separator + "Kaghaz Divari/" + getidtoextra + "_KD.jpg";
DownloadRequest request = new DownloadRequest()
.setDownloadId(pos)
.setUrl("http://www.wenenus.com/www.samankd.com/android/wallpaper/download.php?id=" + getidtoextra)
.setDestFilePath(destPath)
.setDownloadListener(new DownloadListener() {
#Override
public void onStart(int downloadId, long totalBytes) {
}
#Override
public void onRetry(int downloadId) {
itemprogress.setProgress(0);
}
#Override
public void onProgress(int downloadId, long bytesWritten, long totalBytes) {
itemprogress.setProgress((int) ((bytesWritten * 100) / totalBytes));
}
#Override
public void onSuccess(int downloadId, String filePath) {
itemprogress.setVisibility(View.GONE);
}
#Override
public void onFailure(int downloadId, int statusCode, String errMsg) {
itemprogress.setVisibility(View.GONE);
}
});
manager.add(request);
return onLongListItemClick(v,pos,id);
}
});
My custom adapter
public class CustomListAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<Movie> movieItems;
public CustomListAdapter(Activity activity, List<Movie> movieItems) {
this.activity = activity;
this.movieItems = movieItems;
}
#Override
public int getCount() {
return movieItems.size();
}
#Override
public Object getItem(int location) {
return movieItems.get(location);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null) inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) convertView = inflater.inflate(R.layout.list_row, null);
ImageView thumbNail = (ImageView) convertView.findViewById(R.id.thumbnail);
ImageView isdownloaded = (ImageView) convertView.findViewById(R.id.isdownloaded);
LinearLayout newwallpaperarea = (LinearLayout) convertView.findViewById(R.id.newwallpaperarea);
TextView downloads = (TextView)convertView.findViewById(R.id.dlstxt);
TextView rating = (TextView)convertView.findViewById(R.id.ratingtxt);
TextView wallid = (TextView)convertView.findViewById(R.id.wallid);
// getting movie data for the row
Movie m = movieItems.get(position);
File is_wall_dl = new File(Environment.getExternalStorageDirectory()+ "/Kaghaz Divari/"+m.getThumbnailUrl());
File is_wall_dl_id = new File(Environment.getExternalStorageDirectory()+ "/Kaghaz Divari/"+m.getId()+"_KD.jpg");
if(is_wall_dl.exists() || is_wall_dl_id.exists()){
isdownloaded.setVisibility(View.VISIBLE);
}
else{
isdownloaded.setVisibility(View.GONE);
}
Long tsLong = System.currentTimeMillis()/1000;
String ts = tsLong.toString();
String tsnew = ts+"000";
long realtime = Long.parseLong(tsnew);
String walldate = m.getDate();
long walldateall = Long.parseLong(walldate);
long walldatefinal = walldateall+86400000;
if (realtime > walldatefinal) {
newwallpaperarea.setVisibility(View.GONE);
} else {
newwallpaperarea.setVisibility(View.VISIBLE);
}
// thumbnail image
Ion.with(thumbNail)
.placeholder(R.drawable.skd_small_bg_200x200)
.error(R.drawable.skd_small_bg_200x200_error)
.load("http://www.wenenus.com/www.samankd.com/android/wallpaper/wallpaper/200/200/80/1/" + m.getThumbnailUrl());
downloads.setText(m.getDownloads());
rating.setText(m.getRating());
wallid.setText(m.getId());
return convertView;
}
}
i have a listview for showing products (product Name, product Price and product Description).
I want to show the product description in a webview because i use html code (images,tables,video etc).
Everything is ok on the products list except the product description on the WebView.
When i scroll the listview on the products that they are not visible, the product Description(WebView) is completely wrong, actually it shows descriptions from previous products.
The problem it is inside the GetView function, and although i use a viewHolder class , it still the problem remailns. Below i show the code snippet of the Getview and the viewholder class :
/////THE VIEWHOLDER CLASS THAT HOLDS THE UI COMPONENTS//////////////////
private class ViewHolder {
TextView prName;
WebView prDescription;
TextView product_descr2;//for test, this shows always the correct pr. descr.
TextView prfprice;
ImageView prImage;
ProgressBar prProgressBar;
int ProdPosition;
}
//////THE GETVIEW() FUNCTION , WHERE I LOAD EACH PRODUCT VALUES///////
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
View view = convertView;
final ProductsData info = getItem(position);
if (view == null) {
// Product row
view = mInflater.inflate(R.layout.productslistitem_layout, null);
viewHolder = new ViewHolder();
assert view != null;
viewHolder.prName = (TextView) view.findViewById(R.id.product_name);
viewHolder.prDescription = (WebView) view.findViewById(R.id.webView1);
viewHolder.product_descr2 = (TextView)view.findViewById(R.id.product_descr2);
viewHolder.prDescription.setFocusable(false);
//final price
viewHolder.prfprice = (TextView) view.findViewById(R.id.product_fprice);
viewHolder.prImage = (ImageView) view.findViewById(R.id.product_image);
viewHolder.prProgressBar = (ProgressBar)view.findViewById(R.id.pbProduct);
view.setTag(viewHolder);
}else
viewHolder = (ViewHolder) view.getTag();
MainActivity.imageLoaderProducts.displayImage(info.getPrUrl(), viewHolder.prImage, options, new SimpleImageLoadingListener(){
#Override
public void onLoadingStarted(String imageUri, View view) {
viewHolder.prProgressBar.setProgress(0);
viewHolder.prProgressBar.setVisibility(View.VISIBLE);
}
#Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
viewHolder.prProgressBar.setVisibility(View.GONE);
}
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
viewHolder.prProgressBar.setVisibility(View.GONE);
viewHolder.prName.setText(info.getPrName()); //PRODUCT NAME
viewHolder.product_descr2.setText(info.getPrDescr()));//PRODUCT DESCR, CORRECT VALUES
String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
viewHolder.prDescription.setWebViewClient(new WebViewClient());
viewHolder.prDescription.getSettings().setJavaScriptEnabled(true);
//ENCODING UTF-8
viewHolder.prDescription.getSettings().setDefaultTextEncodingName("utf-8");
viewHolder.prDescription.loadData(header +"<div style='background-color:#fff'>"+ info.getPrDescr()+"</div>", "text/html; charset=utf-8", null);//WBVIEW SHOW WRONG PR.DESCR.
}, new ImageLoadingProgressListener() {
#Override
public void onProgressUpdate(String imageUri, View view, int current,int total) {
viewHolder.prProgressBar.setProgress(Math.round(100.0f * current / total));
}
}
);
return view;
}
The product_descr2(TextView) shows the correct product description but the prDescription(WebView) shows the correct description only for the first product of the list. Is it a bug of WebView component or am i doing something wrong?
If anyone knows any solution please give a hand.
/*******************************/
I noticed that if i add convertview = null; into the getView, it loads the correct values into the WebViews but it is too slow.
i show the code of the products file. I use the universal image loader for lazy loading of the product images.
/******************PRODUCTS FILE************************************************************/
import java.util.ArrayList;
public class FragmentProducts extends Fragment implements
OnItemClickListener {
private ArrayList<ProductsData> productsList;
private ArrayList<ProductBitmapData> ProductBitmapList;
private LayoutInflater mInflater;
private ProductsListAdapter pAdapter;
private GridView lvProducts;
private ImageButton btnRefreshProducts;
private String VarTitle;//vartitle for the cart
private String VarId;//varId for the cart
private float VarPrice;//varPrice for the cart
//NEW for universal image loader
private DisplayImageOptions options;
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onViewCreated(view, savedInstanceState);
//change fonts
TextView tvProductsHeader = (TextView)getActivity().findViewById(R.id.tvProductsHeader);
Utils.TypeFace(tvProductsHeader, getActivity().getAssets());
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
mInflater = getActivity().getLayoutInflater();
pAdapter = new ProductsListAdapter(getActivity(), productsList);
lvProducts.setAdapter(pAdapter);
}
public static final FragmentProducts newInstance(
ArrayList<ProductsData> productsList,
ArrayList<ProductBitmapData> ProductBitmapList) {
FragmentProducts fr = new FragmentProducts();
Bundle args = new Bundle();
args.putSerializable("products", productsList);
args.putSerializable("bitmaps", ProductBitmapList);
fr.setArguments(args);
return fr;
}
public static final FragmentProducts newInstance(
ArrayList<ProductsData> productsList) {
//OLD FragmentProductsList fr = new FragmentProductsList();
FragmentProducts fr = new FragmentProducts();
Bundle args = new Bundle();
args.putSerializable("products", productsList);
fr.setArguments(args);
return fr;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.productsList = (ArrayList<ProductsData>) (getArguments() != null ? getArguments()
.getSerializable("products") : null);
this.ProductBitmapList = (ArrayList<ProductBitmapData>) (getArguments() != null ? getArguments()
.getSerializable("bitmaps") : null);
//display options
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_stub)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.bitmapConfig(Bitmap.Config.RGB_565)
.build();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.productslist_layout, container,
false);
lvProducts = (GridView) view.findViewById(R.id.glist);
lvProducts.setOnItemClickListener(this);
btnRefreshProducts = (ImageButton) view
.findViewById(R.id.btnRefreshProducts);
btnRefreshProducts.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
pAdapter = new ProductsListAdapter(getActivity(), productsList);
lvProducts.setAdapter(pAdapter);
}
});
return view;
}
// CUSTOM ARRAY ADAPTER FOR THE LIST of CATEGORY ITEMS
public class ProductsListAdapter extends ArrayAdapter<ProductsData> {
public ProductsListAdapter(Context context, ArrayList<ProductsData> data) {
super(context, 0, data);
}
private class ViewHolder {
TextView prName;
WebView prDescription;
TextView prfprice;
ImageView prImage;
ProgressBar prProgressBar;
Spinner PrVariants1;
Spinner PrVariants2;
int ProdPosition;
//adapters
ArrayAdapter<String> var1Adapter;
ArrayAdapter<String> var2Adapter;
}
#Override
public int getCount() {
return super.getCount();
}
#Override
public ProductsData getItem(int position) {
return super.getItem(position);
}
#Override
public long getItemId(int position) {
return super.getItemId(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder viewHolder;
/*Clear convert view , and the WEBVIEW(DESCRIPTION) WORKS FINE! **/
/*BUT IT IS TOO SLOW BECAUSE, IT LOADS FROM THE START EACH TIME*/
convertView = null;
/*************************/
View view = convertView;
final ProductsData info = getItem(position);
if (view == null) {
// Product row
view = mInflater.inflate(R.layout.productslistitem_layout, null);
viewHolder = new ViewHolder();
assert view != null;
viewHolder.prName = (TextView) view.findViewById(R.id.product_name);
viewHolder.prDescription = (WebView) view.findViewById(R.id.webView1);
viewHolder.prDescription.setFocusable(false);
//starting price
/*viewHolder.prsprice = (TextView) view.findViewById(R.id.product_sprice);*/
//final price
viewHolder.prfprice = (TextView) view.findViewById(R.id.product_fprice);
viewHolder.prImage = (ImageView) view.findViewById(R.id.product_image);
viewHolder.prProgressBar = (ProgressBar)view.findViewById(R.id.pbProduct);
viewHolder.PrVariants1 = (Spinner) view.findViewById(R.id.spOptions1);
viewHolder.PrVariants1.setFocusable(false);
viewHolder.PrVariants2 = (Spinner) view.findViewById(R.id.spOptions2);
viewHolder.PrVariants2.setFocusable(false);
view.setTag(viewHolder);
}else
viewHolder = (ViewHolder) view.getTag();
MainActivity.imageLoaderProducts.displayImage(info.getPrUrl(), viewHolder.prImage, options, new SimpleImageLoadingListener(){
#Override
public void onLoadingStarted(String imageUri, View view) {
viewHolder.prProgressBar.setProgress(0);
viewHolder.prProgressBar.setVisibility(View.VISIBLE);
}
#Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
viewHolder.prProgressBar.setVisibility(View.GONE);
}
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
viewHolder.prProgressBar.setVisibility(View.GONE);
viewHolder.prName.setText(info.getPrName());
//SHOW WEBVIEW PRODUCT VALUE
String header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
viewHolder.prDescription.setWebViewClient(new WebViewClient());
viewHolder.prDescription.getSettings().setJavaScriptEnabled(true);
//ENCODING UTF-8
viewHolder.prDescription.getSettings().setDefaultTextEncodingName("utf-8");
/**HERE IS THE PROBLEM ,I LOAD THE info.PrComments(product description)*/
viewHolder.prDescription.loadData(header +"<div style='background-color:#fff'>"+ info.getPrComments()+"</div>", "text/html; charset=utf-8", null);
/****************AND IF I SCROLL THE WEBVIEW VALUES ARE CONFUSED ***********/
/********START FILL VARIANTS 1 & 2***********/
viewHolder.var1Adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item);
viewHolder.var2Adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item);
//product id
int tempPrid = info.getPrID();
//new variants1
//LOAD variant1
for(int i = 0; i < info.getVariantsItems().size(); i ++){
viewHolder.var1Adapter.add(info.getVariantsItems().get(i).getVarOptions1());
}
//IF VARIANT2 IS NULL, View.GONE
if(info.getVariantsItems2().get(0).getVarOptions2() != null){
for(int i = 0; i < info.getVariantsItems2().size(); i ++){
viewHolder.var2Adapter.add(info.getVariantsItems2().get(i).getVarOptions2());
}
viewHolder.var2Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
viewHolder.PrVariants2.setAdapter(viewHolder.var2Adapter);
}//end if
else{
viewHolder.PrVariants2.setVisibility(View.GONE);
}//end else variant2
viewHolder.var1Adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
viewHolder.PrVariants1.setAdapter(viewHolder.var1Adapter);
//add eventListener on variants1 listbox
viewHolder.PrVariants1.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View arg1, int pos, long arg3) {
//GET VALUES FROM spinner1
String tempOption1 = parent.getItemAtPosition(pos).toString();
//initialize
String tempOption2=null;
//CHECK IF SPINNER2 IS VISIBLE(IF IT IS VISIBLE ,IT HAS VALUE)
if (viewHolder.PrVariants2.getVisibility() != View.GONE){
if (viewHolder.PrVariants2.getSelectedItem() != null){
tempOption2 = viewHolder.PrVariants2.getSelectedItem().toString();
}
}
if (tempOption2 !=null)
{
VarTitle = tempOption1 + "/" + tempOption2;
}else
VarTitle = tempOption1;
ArrayList<String> res = MainApplication.dbHelper.checkVariation(VarTitle, Integer.toString(info.getPrID()));
//IF VARIATION DOES NOT EXIST , price field = N/A
if (res.isEmpty())
viewHolder.prfprice.setText("N/A");
else{
viewHolder.prfprice.setText(res.get(1) + "€");
VarId = res.get(0);//get the variantId for the cart
VarPrice = Float.valueOf(res.get(1));//get the variant price for the cart
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {}
});
//add event listener on variants2 listbox
viewHolder.PrVariants2.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View arg1, int pos, long arg3) {
//initialize
String tempOption2 = null;
if(parent.getItemAtPosition(pos) != null){
tempOption2 = parent.getItemAtPosition(pos).toString();
}
//GET SPINNER1 VALUE
String tempOption1 = viewHolder.PrVariants1.getSelectedItem().toString();
if(tempOption2 != null)
{
VarTitle = tempOption1 + "/" + tempOption2;
}else
VarTitle = tempOption1;
ArrayList<String> res = MainApplication.dbHelper.checkVariation(VarTitle, Integer.toString(info.getPrID()));
///IF VARIATION DOES NOT EXIST , price field = N/A
if (res.isEmpty())
viewHolder.prfprice.setText("N/A");
else{
viewHolder.prfprice.setText(res.get(1) + "€");
VarId = res.get(0);//get the variantId for the cart
VarPrice = Float.valueOf(res.get(1));//get the variant price for the cart
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {}
});
/********END FILL VARIANTS 1 & 2*************/
}
}, new ImageLoadingProgressListener() {
#Override
public void onProgressUpdate(String imageUri, View view, int current,
int total) {
viewHolder.prProgressBar.setProgress(Math.round(100.0f * current / total));
}
}
);
return view;
}
}
Don't use ViewHolder! => http://blog.xebia.com/2013/07/22/viewholder-considered-harmful/
try this:
...without if(convert == null){ ....
just inflate convertView
#Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = Inflater.inflate(R.layout.productslistitem_layout, null);
...
...
I've done XML parsing to ListView and right now do i need to implement load-more feature. I know how to indicat, when the user scrolled to the bottom and how to limit the number of items in a ListView. But is there any way how to show more items when the user scrolls to the end of the list?
Here is my adapter class:
public class ClubsAdapter extends ArrayAdapter<LeagueClub> {
ImageLoader imageLoader;
DisplayImageOptions options;
Context mContext;
public static List<LeagueClub> mClubs;
#SuppressWarnings("deprecation")
public ClubsAdapter(Context mContext, int textViewResourceId, List<LeagueClub> clubs) {
super(mContext, textViewResourceId, clubs);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(mContext).build();
imageLoader = ImageLoader.getInstance();
imageLoader.init(config);
options = new DisplayImageOptions.Builder()
.cacheInMemory()
.cacheOnDisc()
.build();
mClubs=clubs;
}
#Override
public View getView(int pos, View convertView, ViewGroup parent){
RelativeLayout row = (RelativeLayout)convertView;
Log.i("PremierLeague", "getView pos = " + pos);
if(null == row){
LayoutInflater inflater = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = (RelativeLayout)inflater.inflate(R.layout.row_site, null);
}
final ImageView clubLogo = (ImageView)row.findViewById(R.id.clubLogo);
TextView nameTxt = (TextView)row.findViewById(R.id.nameTxt);
TextView aboutTxt = (TextView)row.findViewById(R.id.aboutTxt);
TextView stadiumTxt = (TextView)row.findViewById(R.id.stadiumTxt);
final ProgressBar indicator = (ProgressBar)row.findViewById(R.id.progress);
indicator.setVisibility(View.VISIBLE);
clubLogo.setVisibility(View.INVISIBLE);
ImageLoadingListener listener = new ImageLoadingListener(){
#Override
public void onLoadingStarted(String arg0, View arg1) {
// TODO Auto-generated method stub
}
#Override
public void onLoadingCancelled(String arg0, View arg1) {
// TODO Auto-generated method stub
}
#Override
public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
indicator.setVisibility(View.INVISIBLE);
clubLogo.setVisibility(View.VISIBLE);
}
#Override
public void onLoadingFailed(String arg0, View view, FailReason arg2) {
indicator.setVisibility(View.INVISIBLE);
ImageView imageView = (ImageView) view.findViewById(R.id.clubLogo);
imageView.setVisibility(View.VISIBLE);
}
};
imageLoader.displayImage(getItem(pos).getLogo(), clubLogo,options, listener);
nameTxt.setText(getItem(pos).getName());
aboutTxt.setText(getItem(pos).getAbout());
stadiumTxt.setText(getItem(pos).getStadium());
return row;
}
public int getCount() {
return mClubs.size(); //If i set return 10; it limits items to max 10
}
}
And here is my Fragment:
public class Fragment2 extends Fragment {
static PullToRefreshListView mListView;
static ClubsAdapter mAdapter;
Context mContext;
ProgressBar mProgress;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_2, container, false);
mListView = (PullToRefreshListView) rootView.findViewById(R.id.pull_to_refresh_listview1);
mProgress = (ProgressBar) rootView.findViewById(R.id.loading_clubs);
mProgress.setVisibility(View.VISIBLE);
ClubsDownloadTask task = new ClubsDownloadTask();
task.execute();
mListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
#Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
// Do work to refresh the list here.
mProgress.setVisibility(View.INVISIBLE);
ClubsDownloadTask task = new ClubsDownloadTask();
task.execute();
}
});
return rootView;
}
private class ClubsDownloadTask extends AsyncTask<Void, Void, Void>{
private ClubsAdapter mAdapter;
#Override
protected Void doInBackground(Void... arg0) {
try {
Downloader.DownloadFromUrl("http://dl.dropboxusercontent.com/s/h2qc41k2yy3c1ir/clubs.xml", getActivity().openFileOutput("clubs.xml", Context.MODE_PRIVATE));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return null;
}
protected void onPreExecute() {
}
protected void onPostExecute(Void result){
mListView.onRefreshComplete();
mProgress.setVisibility(View.INVISIBLE);
mAdapter = new ClubsAdapter(getActivity(), -1 , ClubsXmlPullParser.getItemsFromFile(getActivity()));
mListView.setAdapter(mAdapter);
if(ClubsAdapter.mClubs != null){
mAdapter.clear();
for (int i = 0; i < ClubsAdapter.mClubs.size(); i++) {
mAdapter.add(ClubsAdapter.mClubs.get(i));
}
mListView.setOnScrollListener(new OnScrollListener() {
#Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
if(mListView.getRefreshableView().getCount()!=0&&mListView.getRefreshableView().getCount()>0&&mAdapter.getCount()!=0){
if (mListView.getRefreshableView().getLastVisiblePosition() == mListView.getRefreshableView().getAdapter().getCount() - 1
&& mListView.getRefreshableView()
.getChildAt(mListView.getRefreshableView().getChildCount() - 1)
.getBottom() <= mListView.getRefreshableView().getHeight()) {
//Here do I need to load more items
}
}
}
#Override
public void onScrollStateChanged(AbsListView view,
int scrollState) {
if (SCROLL_STATE_TOUCH_SCROLL == scrollState) {
View currentFocus = getActivity().getCurrentFocus();
if(currentFocus != null) {
currentFocus.clearFocus();
}
}
}
});
}
}
}
}
Thanks for any suggestion!
You can use this adapter https://github.com/commonsguy/cwac-endless
With this adapter, when user scroll to end of list, it will call a function which you can implement to load more items.