I am bind the adapter with listview and at first I have fetch 10 records then when I scroll ends then again the items added in listview and it works perfect.
But when I added items after scroll end then at that time items are added successfully then the listview position set to top. I want to set that position to new added items.
Here is my codes:
onscroll function:
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
new items().execute();
}
Async function:
class items extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
...
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("id", String.valueOf(id)));
JSONObject json = jParser.makeHttpRequest(url, "GET",
params);
try {
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
String id = c.getString(TAG_PID);
String name = c.getString(TAG_NAME);
Product item = new Product(name, imageurl);
product_name.add(item);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
adapter = new CategoryAdapter(context, product_name);
category_linear.setAdapter(adapter);
}
Baseadapter:
public class CategoryAdapter extends BaseAdapter {
Context context;
// protected List<String> m_List;
protected List<Product> rowItems;
public CategoryAdapter(Context context, List<Product> items) {
this.context = context;
this.rowItems = items;
}
public void addItemAll(List<Product> item) {
//
rowItems.addAll(item);
notifyDataSetChanged();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return rowItems.size();
}
@Override
public Object getItem(int position) {
return rowItems.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
convertView = LayoutInflater.from(getActivity()).inflate(
R.layout.row, null);
}
Product rowItem = (Product) getItem(position);
TextView text = ViewHolderPattern.get(convertView, R.id.item_name);
text.setText(rowItem.getTitle());
return convertView;
}
}
Now how can I set the position of scroll while new items is added.
currently when new items added then it will go to top of the listview.
But I want to set the position to the new items starting.
How can I do this?