0

这条线不会设置,holder.t1.setText(NewItem);

如果我将它移到 parent onClick,使用硬编码字符串(用于测试)它会。

请记住,这是在 .getView 方法中ArrayAdapter。我正在尝试将 setText 设置为ListView行。

编辑:

扩展,完成 getView() -- 按要求(没有时间编辑,稍后会,抱歉!)

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;

    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if (convertView == null) {

        convertView = inflater.inflate(R.layout.commentlayout, parent,
                false);
        holder = new ViewHolder();
        holder.t1 = (TextView) convertView.findViewById(R.id.labelComment);
        holder.t2 = (TextView) convertView.findViewById(R.id.labelDate);
        holder.t3 = (TextView) convertView.findViewById(R.id.labelUser);
        holder.t3.setTypeface(tf);
        holder.t4 = (TextView) convertView
                .findViewById(R.id.labelHelpfulCount);
        holder.t5 = (TextView) convertView
                .findViewById(R.id.labelCommentCount);
        holder.ib1 = (ImageView) convertView
                .findViewById(R.id.labelChatIcon);
        holder.ib2 = (ImageView) convertView
                .findViewById(R.id.labelCommentFlag);
        holder.rb1 = (RatingBar) convertView
                .findViewById(R.id.myCommentsRatingBarSmall);
        holder.b1 = (Button) convertView.findViewById(R.id.bReview1);
        holder.b2 = (Button) convertView.findViewById(R.id.bReview2);
        holder.b3 = (Button) convertView.findViewById(R.id.bReview3);

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
        convertView.setOnCreateContextMenuListener(null);
    }

    ReviewObject ro = getItem(position);
    final String item = ro.item;
    final String review = ro.review;
    final String username = ro.username;
    Long date = Long.valueOf(ro.date);
    String rating = ro.ratings;
    String voteCount = ro.voteCount;
    String chatcount = ro.chatCount;
    String cat = ro.cat;

    final ArrayList<String> passing = new ArrayList<String>();
    passing.add(item);
    passing.add(review);
    passing.add(cat);
    passing.add(username);

    String time = "";
    time = DateConvert.dateConvert(Long.valueOf(date));

    holder.t1.setText(review);
    holder.t2.setText(time);
    holder.t3.setText(username);
    holder.t4.setText(voteCount);
    holder.t5.setText(chatcount);
    holder.ib1.setImageResource(R.drawable.updown);
    holder.ib2.setImageResource(R.drawable.comment);
    holder.rb1.setRating(Float.valueOf(rating));

    if (rating.equals("0")) {
        holder.rb1.setEnabled(false);
    }

    holder.b1.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            String ReviewUser = holder.t3.getText().toString();
            String ReviewWords = holder.t1.getText().toString();

            Intent intent = new Intent(getContext(), Comments.class);
            intent.putExtra("comment", ReviewWords);
            intent.putExtra("user", ReviewUser);
            intent.putExtra("item", item);
            getContext().startActivity(intent);

        }
    });

    if (!Rateit.username.equals(username)) {

        holder.b2.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                AlertDialog.Builder alertbox = new AlertDialog.Builder(getContext());
                alertbox.setMessage("Did you like this?");
                alertbox.setNegativeButton("Vote Up",
                        new DialogInterface.OnClickListener() {

                            @SuppressWarnings("unchecked")
                            public void onClick(DialogInterface arg0,
                                    int arg1) {

                                String VoteTally = holder.t4.getText()
                                        .toString();
                                int ReviewCountInt = Integer
                                        .valueOf(VoteTally) + 1;
                                VoteTally = String.valueOf(ReviewCountInt);
                                holder.t4.setText(VoteTally);

                                new HelpfulTask().execute(passing);
                            }
                        });

                alertbox.setPositiveButton("Vote Down",
                        new DialogInterface.OnClickListener() {

                            @SuppressWarnings("unchecked")
                            public void onClick(DialogInterface dialog,
                                    int id) {

                                String VoteTally = holder.t4.getText()
                                        .toString();
                                int ReviewCountInt = Integer
                                        .valueOf(VoteTally) - 1;
                                VoteTally = String.valueOf(ReviewCountInt);
                                holder.t4.setText(VoteTally);

                                new UnHelpfulTask().execute(passing);

                            }
                        });

                alertbox.setNeutralButton("Report Spam",
                        new DialogInterface.OnClickListener() {

                            @SuppressWarnings("unchecked")
                            public void onClick(DialogInterface dialog,
                                    int id) {

                                new SpamTask().execute(passing);

                            }
                        });

                alertbox.show();

            }

        });

    } else {
        holder.b2.setText("Edit");
        holder.b2.setOnClickListener(new OnClickListener() {



            public void onClick(View v) {

                final Dialog dialog = new Dialog(getContext());
                dialog.setContentView(R.layout.editreview);
                dialog.setTitle("Edit Review");
                dialog.show();

                final EditText etEdit = (EditText) dialog
                        .findViewById(R.id.etEditReview);

                etEdit.setText(review);

                Button bInsert = (Button) dialog.findViewById(R.id.bInsert);
                bInsert.setOnClickListener(new OnClickListener() {

                    @SuppressWarnings("unchecked")
                    public void onClick(View v) {


                        NewItem = etEdit.getText().toString();


                        if (NewItem.equals("")) {

                            Toast.makeText(getContext(),
                                    "Please add something first.",
                                    Toast.LENGTH_SHORT).show();

                        } else {

                            holder.t1.setText(NewItem);
                            passing.add(NewItem);

                            dialog.dismiss();

                            new EditCommentTask().execute(passing);


                        }

                    }
                });

            }
        });

    }

    if (!Rateit.username.equals(username)) {

        holder.b3.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent i = new Intent(getContext(), OtherProfile.class);
                i.putExtra("userprofile", username);
                getContext().startActivity(i);

            }
        });

    } else {
        holder.b3.setText("Delete");
        holder.b3.setOnClickListener(new OnClickListener() {
            @SuppressWarnings("unchecked")
            public void onClick(View v) {

                AlertDialog.Builder alertbox = new AlertDialog.Builder(
                        getContext());
                alertbox.setMessage("Are you sure you want to delete your review?");
                alertbox.setNegativeButton("No",
                        new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface arg0,
                                    int arg1) {

                            }
                        });

                alertbox.setPositiveButton("Yes",
                        new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog,
                                    int id) {

                                new DeleteReviewTask().execute(passing);


                            }
                        });

                alertbox.show();

            }
        });

    }

    return convertView;
}
4

1 回答 1

0

根据您在上述评论中所说的,这是预期的功能。自从,

除了对话框确实关闭,我得到了祝酒词并且任务正确运行。

这被编码到您的 onClick() 中:

bInsert.setOnClickListener(new OnClickListener() {

                @SuppressWarnings("unchecked")
                public void onClick(View v) {

                    NewItem = etEdit.getText().toString();

                    if (NewItem.equals("")) {

                        Toast.makeText(getContext(),
                                "Please add something first.",
                                Toast.LENGTH_SHORT).show();
                    } else {

                        holder.t1.setText(NewItem);
                        passing.add(NewItem);

                        dialog.dismiss();

                        new EditCommentTask().execute(passing);
                    }
                }
            });

具体来说,这是执行:

 if (NewItem.equals("")) {
   Toast.makeText(getContext(),
      "Please add something first.",
      Toast.LENGTH_SHORT).show();
 }

所以我假设你的问题是NewItem,我从来没有看到你实际初始化它的位置,但我假设它是.equals("")因为它正在执行。尝试将 aLog.dprintln()正好放在该线下方NewItem = etEdit.getText().toString();,看看此时的值NewItem是多少。

于 2013-01-28T00:46:46.460 回答