I want to display first 10 item continue to upload to 10 item when they reach the end of the list. The error: "The method setOnScrollListener(AbsListView.OnScrollListener) in the type AbsListView is not applicable for the arguments (new Runnable(){})" in line list=getListView().setOnScrollListener(this);. How to fix?
public class CustomizedListView extends ListActivity implements OnScrollListener{
private ProgressDialog pDialog;
// All static variables
static final String URL = "https://api.api2cart.com/v1.0/product.list.xml?api_key=6aed775211e8c3d556db063d12125d2d&store_key=ed58a22dfecb405a50ea3ea56979360d&start=0&count=19¶ms=id,u_model,name,price,images,short_description";
// XML node keys
static final String KEY_SONG = "product"; // parent node
static final String KEY_ID = "id";
static final String KEY_TITLE = "u_model";
static final String KEY_ARTIST = "name";
static final String KEY_DURATION = "price";
static final String KEY_THUMB_URL = "http_path";
static final String KEY_SHORT_DESCRIPTION = "short_description";
ListView list;
LazyAdapter adapter;
ArrayList<HashMap<String, String>> songsList;
//@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
songsList = new ArrayList<HashMap<String, String>>();
new LoadCatalog().execute();
}
public void onScroll(AbsListView view, int firstVisible, int visibleCount, int totalCount) {
boolean loadMore = /* maybe add a padding */
firstVisible + visibleCount >= totalCount;
if(loadMore) {
adapter.count += visibleCount; // or any other amount
adapter.notifyDataSetChanged();
}
}
public void onScrollStateChanged(AbsListView v, int s) { }
class LoadCatalog extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(CustomizedListView.this);
pDialog.setMessage("Загрузка каталога ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_SONG);
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_ID, parser.getValue(e, KEY_ID));
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
map.put(KEY_SHORT_DESCRIPTION, parser.getValue(e, KEY_SHORT_DESCRIPTION));
map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));
// adding HashList to ArrayList
songsList.add(map);
}
return null;
}
public void onScroll(AbsListView view, int firstVisible, int visibleCount, int totalCount) {
boolean loadMore = /* maybe add a padding */
firstVisible + visibleCount >= totalCount;
if(loadMore) {
adapter.count += visibleCount; // or any other amount
adapter.notifyDataSetChanged();
}
}
public void onScrollStateChanged(AbsListView v, int s) { }
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
list=getListView().setOnScrollListener(this);
adapter=new LazyAdapter(CustomizedListView.this, songsList);
list.setAdapter(adapter);
}
});
} }}
Change "this" for CustomizedListView.this, with "this" you are actually refering to the Runnable Object you created inside the parameters of runOnUiThread method, you should point to the class that implements the Scroll Listener by using "CustomizedListView.this" (in case CustomizedListView implements the Scroll Listener interface)
Hope this Helps.
Regards