Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6681051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:32:47+00:00 2026-05-26T04:32:47+00:00

I have a listview in my activity, and when I click on a button

  • 0

I have a listview in my activity, and when I click on a button a dialog is opened in this way:

private void openDialog(){
    AlertDialog.Builder builder = new AlertDialog.Builder(FriendActivity.this);
    builder.setTitle("Add friend");
    builder.setMessage("Add the name and the phone number for your friend.");
    LayoutInflater fi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = fi.inflate(R.layout.friend_dialog, null);
    final EditText name = (EditText) v.findViewById(R.id.edit1);
    final EditText number = (EditText) v.findViewById(R.id.edit2);

    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String namee = name.getText().toString().trim();
            String numberr = number.getText().toString().trim();
            db.insertFriend(namee, numberr);
            //updateAdapter();
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // do nothing
        }
    });
    builder.setView(v);
    builder.show();
}

Okay, that works!
Problem is when I click on the EditText they keyboard pops up, but when I press back to disable it or even press “OK” to add it, the listview’s elements gets duplicated all the time. I cant see why? Anyone who knows this problem?

Thanks.

UPDATE:

The problem seems to be in my listAdapter =/ when I scroll up or down the text get duplicated for some reason, here’s my code:

 class ListAdapter extends ArrayAdapter<Friend>{

    private ImageView img;
    private TextView name, number;
    private Context context;

    public ListAdapter(Context context, int textViewResourceId, List<Friend> objects) {
        super(context, textViewResourceId, objects);
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        LayoutInflater vi;

        if(v == null){
            vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.row, null);
        }

        Friend item = getItem(position);

        name = (TextView) v.findViewById(R.id.name);
        number = (TextView) v.findViewById(R.id.number);

        name.append(item.getName());
        number.append(item.getNumber());

        return v;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:32:47+00:00Added an answer on May 26, 2026 at 4:32 am

    Did you mean to call name.append and number.append? I think name.setText and number.setText sounds more appropriate. The append methods will keep adding more and more text.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a ListView on which I click to start new Activity called
Actually in my app i have a button on an listView..now on click of
I have an activity in Android which uses a ListView. When I click on
I have to call mapactivity from list activity.whenever user click on item on listview,
I have Activity with ListView inside it and in the onCreate method of the
I have an Activity in Android, with two elements: EditText ListView When my Activity
I have a ListView control, and I'm trying to figure out the easiest/best way
I have the following problem. My main activity consists of a ListView populated with
I have a ListView that uses a customized adapter, but I can't click on
I have listView in which I inflate a row contain textview and button now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.