我想要做的是在底部附加一个列表项,就像“加载更多”功能一样。
我所做的我在适配器中附加了一个带有空值的额外项目ArrayList
。
它第一次工作正常,但是当我加载更多项目时,它会在每 15 个项目后添加两次 Load More ItemView 虽然我没有对 original 进行任何更改ArrayList
。仅对适配器类的构造函数进行了更改。
这是适配器类:
public class ContactListAdaptor extends BaseAdapter {
private Context context;
private ArrayList<DirectroyDetails> items = new ArrayList<DirectroyDetails>();
private Activity activity = null;
boolean isSearch = false;
private View currentView = null;
private String categoryName = null;
private HashMap< String, String> bannerHash = new HashMap<String, String>();
ContactList ACTIVITY;
public ContactListAdaptor(Context context, final ArrayList<DirectroyDetails> items2, Activity activity, String categoryName, HashMap< String, String> bannerHash, ContactList ACTIVITY, boolean expand) {
// super(context, textViewResourceId, items);
items = items2;
if(expand)
{
DirectroyDetails dummy = new DirectroyDetails();
dummy.setId("-1");
items.add(dummy);
}
this.context = context;
this.activity = activity;
this.categoryName = categoryName;
this.bannerHash = bannerHash;
this.ACTIVITY = ACTIVITY;
}
/*public ContactListAdaptor(Context context, Vector<Directory> items,
Activity activity, boolean isSearch) {
// TODO Auto-generated constructor stub
this.items = items;
this.context = context;
this.activity = activity;
this.isSearch = isSearch;
}*/
// @Override
public View getView(final int position, View convertView, ViewGroup parent) {
final DirectroyDetails directroyDetails = items.get(position);
System.out.println("id======="+directroyDetails.getId().toString());
try {
if(convertView == null)
{
System.out.println("##THE POSITION IS=="+position);
LayoutInflater vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.item_directory, null);
if(directroyDetails.getId().toString().equals("-1"))
convertView.setId(-1);
else
convertView.setId(1);
}else {
currentView = convertView;
}
//To fatch the values from the Event object
TextView titleText = (TextView)convertView.findViewById(R.id.title);
TextView nameText = (TextView)convertView.findViewById(R.id.name);
TextView numberText = (TextView)convertView.findViewById(R.id.number);
ImageView profilePic = (ImageView)convertView.findViewById(R.id.eventimage);
System.out.println("the position is ==== " +position);
titleText.setText(directroyDetails.getCompanyname());
nameText.setText(directroyDetails.getFirstname() + " " + directroyDetails.getSurname());
numberText.setText(directroyDetails.getMobile());
System.out.println("id at position======="+directroyDetails.getId().toString()+" at=="+position);
RelativeLayout overlay = (RelativeLayout)convertView.findViewById(R.id.overlay);
if(directroyDetails.getId().toString().equals("-1"))
{
overlay.setVisibility(View.VISIBLE);
System.out.println("at here to make the Overl;ay visible");
}else {
overlay.setVisibility(View.INVISIBLE);
}
} catch (Exception e) {
// TODO: handle exception
System.out.println("the exception occurs at:-" + e.getMessage());
}
return convertView;
}
public int getCount() {
System.out.println("the item size====="+items.size());
return items.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
}
private void onScrollUpdateList() {
// TODO Auto-generated method stub
Handler onScrollList = new Handler();
onScrollList.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
setContactList();
}
}, 200);
}
&这是我的调用代码:-
if(contactDb.size()>0 && contactDb!=null)
{
System.out.println("theh responseData1 before new additions==="+responseData1.size());
responseData1 = addMoreData(contactDb,responseData1);
System.out.println("theh responseData1==="+responseData1.size());
if(responseData1 != null)
{
if(responseData1.size()>0)
{
ContactListAdaptor contactAdaptor = new ContactListAdaptor(getApplicationContext(), responseData1, this, CategoryName, bannerHash, ContactList.this, expand);
contactAdaptor.notifyDataSetChanged();
listview.setAdapter(contactAdaptor);
try {
listview.setSelection(getSelectedItems());
} catch (Exception e) {
// TODO: handle exception
System.out.println("the exception at scrolling and set :- " + e.getMessage());
}
}else
{
Toast.makeText(ContactList.this, "No Item found.", Toast.LENGTH_LONG).show();
}
}}