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 8402657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:07:40+00:00 2026-06-09T22:07:40+00:00

I have a custom ArrayAdapter for a listView in an adroid chat application. I

  • 0

I have a custom ArrayAdapter for a listView in an adroid chat application. I enter some text in my editText component and then i submit the text when i push a button.

The problem is that when the getView method in my custom Adapter is called the entire list is refresh and each row in my list become identically with the last information submitted.

Does someone knows how can i add a row in listView using a custom ArrayAdapter and other rows to have the original text?

This is how i call the adapter:

m_discussionThread = new ArrayList<String>();
    m_discussionThreadAdapter = new ChatListAdapter(this, m_discussionThread);
    list.setAdapter(m_discussionThreadAdapter);

    Button send = (Button) this.findViewById(R.id.send);
    send.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {


            String text = message.getText().toString();

            Message msg = new Message(to, Message.Type.chat);
            msg.setBody(text);
            m_connection.sendPacket(msg);               
            m_discussionThread.add(text);   
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    m_discussionThreadAdapter.notifyDataSetChanged();

                }
            });
        }
    });

This is the adapter:

public ChatListAdapter(Context context, ArrayList<String> chatValue) {  
    super(context,R.layout.list_row_layout_even, chatValue);
    this.context = context;     
    this.chatValue = chatValue;     
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);         
    View rowView  = inflater.inflate(R.layout.list_row_layout_even, parent, false);
    TextView chatText = (TextView) rowView.findViewById(R.id.chat_message);
    chatText.setText(chatValue.get(chatValue.size()-1).toString());
    return rowView;
  • 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-06-09T22:07:41+00:00Added an answer on June 9, 2026 at 10:07 pm

    Near the bottom, you’re getting data element chatValue.size()-1. That means that every View loaded through getView() will have the properties of the last data element. You should instead use position. Example:

    private Context mContext;
    private LayoutInflater mInflater = null;
    
    private ArrayList<String> mChatValue;
    
    public ChatListAdapter(Context context, ArrayList<String> chatValue) {  
        super(context,R.layout.list_row_layout_even, chatValue);
        mContext = context;     
        mChatValue = chatValue;     
    }
    
    private LayoutInflater getInflater(){
        if(mInflater == null)
            mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
        return mInflater;       
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView;
        if(convertView == null) // Only inflating if necessary is great for performance
            rowView = getInflater().inflate(R.layout.list_row_layout_even, parent, false);
        else
            rowView = convertView;
    
        TextView chatText = (TextView) rowView.findViewById(R.id.chat_message);
        chatText.setText(mChatValue.get(position));
    
        return rowView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView that has a custom ArrayAdapter with a custom XML row.
I have used ListView and bounded my custom ArrayAdapter to it. Have setOnItemClickListener(...) bound
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have an activity with a ListView which is populated through a custom ArrayAdapter.
I have a custom ListView that uses a custom ArrayAdapter (which basically just overrides
I have 2 custom ListView Created as item layout + ArrayAdapter + My own
I have a problem with my Android listview. My list uses a custom arrayadapter,
I have a custom xml file for my listview and then I use an
I want to have a listview with a custom adatper, extends ArrayAdapter, where Type
In my application, i have activity group in which i have a custom ListView

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.