在Android中的Baseadaptor中刷新列表

时间:2015-01-18 11:55:36

标签: android list fragment refresh adaptor

  

您好,   我尝试使用我正在制作的推文应用刷新我的数据。当我通过按下“following_del”按钮删除以下人员时,我希望我的列表视图在没有刚刚删除的用户的情况下刷新。你有什么想法吗?我在baseAdaptor类中。感谢

公共类UsersAdapter扩展BaseAdapter实现DialogInterface.OnShowListener {

private List<User> mUsers;
Integer BUTTON_ACTIVATE = 0;

public List<User> getUsers() {
    return mUsers;
}

public Context context;

public void setUsers(List<User> users) {
    mUsers = users;
}

public UsersAdapter(Context context) {
    this.context = context;
}

@Override
public int getCount() {
    return mUsers != null ? mUsers.size() : 0;
}

@Override
public User getItem(int position) {
    return mUsers.get(position);
}


@Override
public long getItemId(int position) {
    // if (getItem(position).getId() == null) {
    return 0;
    //  } else {
    //     return getItem(position).getId().hashCode();
    //  }
}


@Override
public boolean hasStableIds() {
    return true;
}


@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    if (convertView == null) {

        convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.follower_item, parent, false);
        BUTTON_ACTIVATE = 0;

    }

    final User user = getItem(position);
    TextView handleView = (TextView) convertView.findViewById(R.id.handle);
    handleView.setText(user.getHandle());
    TextView statusView = (TextView) convertView.findViewById(R.id.status);
    Log.i(context.getClass().getName(), "Je suis dans ce context2");

    ImageButton button_del = (ImageButton) convertView.findViewById(R.id.add_following);
    button_del.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (AccountManager.isConnected(context)) {
                new AsyncTask<String, Void, Integer>() {
                    @Override
                    protected Integer doInBackground(String... arg) {
                        try {
                            String handle = AccountManager.getUserHandle(context);
                            String token = AccountManager.getUserToken(context);
                            String content = user.getHandle();
                            if (handle.compareTo(content) != 0) {
                                new ApiClient().postdelFollowing(handle, token, content);
                                return 1;
                            }
                        } catch (IOException e) {
                            return 0;
                        }
                    }

                    @Override
                    protected void onPostExecute(Integer success) {
                        if (success == 1) {
                            Toast.makeText(context, "Vous ne suivez plus " + user.getHandle(), Toast.LENGTH_SHORT).show();
                            if (context.getClass().getName().compareTo(FollowingActivity.class.getName()) == 0) {
                                Intent intent = new Intent(context, FollowingActivity.class);
                                intent.putExtras(FollowingFragment.newArgument(UsersFragment.user));
                                context.startActivity(intent);
                            }

                        } else {
                            Toast.makeText(context, "Une erreur s'est produite", Toast.LENGTH_SHORT).show();

                        }
                    }
                }.execute();

            } else {
                new AlertDialog.Builder(context)
                        .setMessage("Veuillez vous connecter")
                        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        })
                        .show();
            }
        }
    });

    return convertView;
}

}

0 个答案:

没有答案