Android ArrayAdapter提供新滚动的项目

时间:2015-12-01 21:07:00

标签: android android-arrayadapter textview

我有一个ArrayAdapter,它使用片段显示一些帖子。在这个片段中,我有一些按钮。所以显示的所有帖子都有这些按钮。 问题是,当我点击帖子的按钮以将setText设置为此帖子的字段时;而不是更改我单击的帖子的文本,它更改新滚动项目的文本。 例如,如果我向下滚动ListView,则会出现一个新项目。然后,无论我点击哪个帖子,都会更改此新帖子的文字。 我怎样才能防止这种情况发生?我使用

获取当前帖子
getItem(position)

通过scroolling我的意思是加载并显示列表的新元素。

public View getView(final int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.comment_small,parent,false);
    TextView tvOwner = (TextView) v.findViewById(R.id.tvCommentSmallOwner);
    TextView tvCreationDate = (TextView) v.findViewById(R.id.tvCommentSmallCreationDate);
    TextView tvCreationDateValue = (TextView) v.findViewById(R.id.tvCommentSmallCreationDate);
    TextView tvContent = (TextView) v.findViewById(R.id.tvCommentSmallContent);
    tvVoteCount = (TextView) v.findViewById(R.id.tvCommentVoteCount);
    c = getItem(position);
    tvOwner.setText(context.getResources().getString(R.string.generic_by) + " " + c.getOwnerId());
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
    String s  =c.getPostDate();
    System.out.println(s);
    tvCreationDateValue.setText(s);
    tvContent.setText(c.getContent());
    btnDownVote = (ImageButton) v.findViewById(R.id.btnCommentDownVote);
    btnUpVote = (ImageButton) v.findViewById(R.id.btnCommentUpVote);


    tvVoteCount.setText("" + c.getNetCount());
    btnUpVote.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            c=getItem(position);
            ServerRequests sr = new ServerRequests(getContext());
            MemberLocalStore memberLocalStore = new MemberLocalStore(getContext());
            Member m = memberLocalStore.getLoggedInMember();
            sr.voteComment(c, true, m.getId(), new Consumer<String>() {
                @Override
                public void accept(String vote) {
                    tvVoteCount.setText("" + vote);
                }
            });
        }
    });

    btnDownVote.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            c=getItem(position);
            ServerRequests sr = new ServerRequests(getContext());
            MemberLocalStore memberLocalStore = new       MemberLocalStore(getContext());
            Member m = memberLocalStore.getLoggedInMember();
            sr.voteComment(c, false, m.getId(), new Consumer<String>() {
                @Override
                public void accept(String vote) {
                    tvVoteCount.setText("" + vote);
                }
            });
        }
    });
    return v;
}

ListView

我想投票(喜欢,不喜欢)一些帖子但是当我点击标记为1的upvote按钮时,标记为2的帖子的整体投票会发生变化。

0 个答案:

没有答案