-1

私がやりたいのは、「もっと読み込む」機能と同じように、リスト項目を一番下に追加することです。

私が実行したことは、空の値を持つ余分なアイテムをアダプターに追加しましたArrayList

初めて正常に動作していますが、さらにアイテムをロードすると、15 アイテムごとに Load More ItemView が 2 回追加されますが、 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();
                }

            }}
4

1 に答える 1

3

以下のリンク コードを確認し、リスト ビューでより多くのデータを動的にロードして問題を解決してください。

http://www.developerfusion.com/article/145373/android-listviews-with-dynamic-data/

ご不明な点がございましたら、お気軽にお問い合わせください..

于 2013-03-28T10:19:32.927 に答える