簡體   English   中英

如何刪除使用簡單光標適配器創建的列表項

[英]how to remove list item created using simple cursor adapter

我想獲取我的電話聯系人列表,並向他們發送邀請消息。 我通過擴展簡單的游標適配器來實現此列表以滿足自己的需求。 現在,我想在從自定義適配器中按下發送按鈕后立即從列表(而不是從我的手機)中刪除聯系人。 請引導我以正確的方式。

到目前為止,這是我所做的:

活動課:

public class NotUsing extends Activity {

    ListView listContacts;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.not_using_kicka);
        final ActionBar actionBar = getActionBar();
        actionBar.setDisplayShowHomeEnabled(false);
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayUseLogoEnabled(false);
        actionBar.hide();

        listContacts = (ListView) findViewById(R.id.not_using_list);

        Uri queryUri = ContactsContract.Contacts.CONTENT_URI;
        String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
                + " COLLATE LOCALIZED ASC";
        // Get All contacts
        CursorLoader cursorLoader = new CursorLoader(this, queryUri, null,
                null, null, sortOrder);

        Cursor cursor = cursorLoader.loadInBackground();

        String[] from = { ContactsContract.Contacts.DISPLAY_NAME,
                ContactsContract.Contacts.PHOTO_THUMBNAIL_URI};
        int[] to = { R.id.phn_contact_name, R.id.phn_contact_img };

        ListAdapter adapter = new NotUsingAdapter(NotUsing.this,
                R.layout.phone_contacts_list, cursor, from, to,
                CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        listContacts.setAdapter(adapter);


    }

}

適配器類:

public class NotUsingAdapter extends SimpleCursorAdapter {

    String Name,PhotoThumbUri;
    int NameField, PhotoThumbField;

    public DisplayImageOptions options;
    private ImageLoader imageLoader = ImageLoader.getInstance();
    private ImageLoadingListener animateFirstListener;
    LibSettings dp;

    public NotUsingAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to, int flags) {
        super(context, layout, c, from, to, flags);

        Name = from[0];
        PhotoThumbUri = from[1];

        NameField = to[0];
        PhotoThumbField = to[1];

        dp = new LibSettings(context);
    }

    public View newView(Context _context, Cursor _cursor, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) _context.getSystemService(_context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.phone_contacts_list, parent, false);
        return view;
    }

    @Override
    public void bindView(final View view, final Context context, final Cursor cursor) {
        final String name = cursor.getString(cursor.getColumnIndex(Name));
        String photoUri = cursor.getString(cursor.getColumnIndex(PhotoThumbUri));

        TextView contactName = (TextView) view.findViewById(NameField);
        contactName.setText(name);

        ImageView contactImage = (ImageView) view.findViewById(PhotoThumbField);

        options = new DisplayImageOptions.Builder()
            .showImageForEmptyUri(R.drawable.picture_blank_square)
            .showImageOnFail(R.drawable.picture_blank_square)
            .cacheInMemory(true)
            .cacheOnDisc(true)
            .considerExifParams(true)
            .displayer(new RoundedBitmapDisplayer(dp.convertPxtoDip(400)))
            .build();
        imageLoader.displayImage(photoUri, contactImage, options, animateFirstListener);

        ImageButton AddFrnd = (ImageButton) view.findViewById(R.id.add_frnd);

        AddFrnd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View btnview) {
                Animation fadeOut = AnimationUtils.loadAnimation(context, R.anim.request_animate);
                fadeOut.setAnimationListener(new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                        UserSession user = new UserSession(context);
                        String UserName = user.getLoginId();
                        //new SmsSend(context).execute("+61431977481",UserName);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        Toast.makeText(context, name, Toast.LENGTH_LONG).show();
                        view.setVisibility(View.GONE);


                        //notifyDataSetChanged();
                    }
                });

                view.startAnimation(fadeOut);
            }
        });


    }
}

您應該從適配器中刪除聯系人項,制作動畫並調用notifyDatasetChanged()。

此操作不會影響您的電話聯系人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM