【问题标题】:how to remove list item created using simple cursor adapter如何删除使用简单光标适配器创建的列表项
【发布时间】:2014-04-22 08:49:17
【问题描述】:

我想获取我的电话联系人列表并向他们发送邀请消息。我通过扩展简单的光标适配器来满足我的需要来实现列表。现在我想在自定义适配器按下发送按钮后从列表中删除一个联系人(但不是从我的手机中)。请指导我正确的方式。

这是我到目前为止所做的:

活动类:

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);
            }
        });


    }
}

【问题讨论】:

    标签: android simplecursoradapter contact-list


    【解决方案1】:

    您应该从适配器中删除联系人项目,制作动画并调用 notifyDatasetChanged()。

    此操作不会触及您的手机联系人。

    【讨论】:

    • 我是安卓新手。我想从适配器内部操作动画和删除。我可以这样做吗?我正在编辑我的帖子并提交我的适配器和活动。请指导我..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多