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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:23:31+00:00 2026-05-25T20:23:31+00:00

Hi i am having a strange trouble, i am not gettings bubble for example

  • 0

enter image description here

Hi i am having a strange trouble, i am not gettings bubble for example you messeges on right and mine on left… when ever i call notifydatachanges it erases all the bubbles…plz guide me. below is the code…

private final Handler mHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {

        if(D) Log.d(TAG, "In the Handler");
        switch (msg.what) {
            case PACKET_CAME:
                String incomingMessage = (String) msg.obj;
                receivedMessages.add("You: " + incomingMessage);

                mg = new Message();
                mg.what = 1;
                updateListHandler.sendMessage(mg);

       //         mAdapter.notifyDataSetChanged();

       //       mAdapter.notifyDataSetInvalidated();

                break;
            case TOAST:
                String toastToMake= (String) msg.obj;
                Toast.makeText(getApplicationContext(), toastToMake,    Toast.LENGTH_SHORT).show();
                break;               
        }
      }
    };   

/** Called when the activity is first created. */
     @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    send    = (Button)findViewById(R.id.send);
    send.setOnClickListener(send_listener);

    //msgList.setTextFilterEnabled(true);


    msg     = (EditText)findViewById(R.id.msg);
    msg.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-up event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_UP) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER)) {
                postMessage();
                return true;
            }
            return false;
        }
    });

    // Start my server thread
    myThread = new ServerThread(getApplicationContext(),mHandler);

    //Check if it's running
    if (!myThread.socketIsOK()){
       Log.e(TAG,"Server NOT STARTED");
       Toast.makeText(getApplicationContext(), "Cannot Start Server: ", Toast.LENGTH_LONG).show();
       return;
     }

       // All appears to be OK, start the main loop
       myThread.start();
       Log.i(TAG,"Server Started");


     msgList = (ListView)findViewById(R.id.msgList);
     mAdapter = new CustomAdapter();
     msgList.setAdapter(mAdapter);


    }// end OnCreate()

   public class CustomAdapter extends BaseAdapter {
    public CustomAdapter(){
    // TODO Auto-generated constructor stub
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {         

            LayoutInflater inflater = getLayoutInflater();
            View row = null;
            Log.i("sentmsg", Integer.toString(sentmsg));
            Log.i("revmsg", Integer.toString(recvmsg));

            if(sentmsg == 1){
                row = inflater.inflate(R.layout.message, parent, false);
                TextView tv =   (TextView)row.findViewById(R.id.textmsg);       
                tv.setText(receivedMessages.get(position));                 
                sentmsg = 0;
            }else{
                row = inflater.inflate(R.layout.messagert, parent, false);
                TextView tv = (TextView)row.findViewById(R.id.textmsg);     
                tv.setText(receivedMessages.get(position));                 
            }


            return row;
        }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return receivedMessages.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }
    }


  // Sends the message in the msg EditText
   private void postMessage(){
    String theNewMessage = msg.getText().toString();

    try{
        myThread.sendMessage(theNewMessage);
    }catch(Exception e){
        Log.e(TAG,"Cannot send message"+e.getMessage());
    }
    sentmsg = 1;
    receivedMessages.add("Me: " + theNewMessage);

    Message msg = new Message();
    msg.what = 1;
    updateListHandler.sendMessage(msg);

  //    msgList.invalidateViews();
  //  mAdapter.notifyDataSetChanged();
  //  mAdapter.notifyDataSetInvalidated();
  //  msgList.invalidateViews();
  }

  private Handler updateListHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
        case 1:
            mAdapter.notifyDataSetChanged();
            break;
        }
        ;
    };
   };





  // On click listener for the button
  private OnClickListener send_listener = new OnClickListener() {
    public void onClick(View v) {
        postMessage();
    }
  };

  @Override
  public void onDestroy(){
    super.onDestroy();
    myThread.closeSocket();
  }

   }// Activity class

This is the xml

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textmsg"
android:layout_marginTop="2px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp" 
android:background="@drawable/greybox">
 </TextView>
</LinearLayout>

this is another xml

 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/textmsg"
 android:layout_marginTop="2px"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:padding="10dp"
 android:textSize="16sp">
 </TextView>  
 </LinearLayout>

greybox is 9 patch image.
The sentmsg acts like a flag so that i can inflate the required row according to message recevied or sent…

  • 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-25T20:23:31+00:00Added an answer on May 25, 2026 at 8:23 pm

    You have not organised your chat data properly. Have a class that holds a chat message and its sender id.

    class Message {
       int senderId;
       String message;
    }
    

    Use this object to create the list of chat messages. Then in adapter’s getview method do this

    Message msg = messageList.get(position);
    if (msg.getSenderId() == getMyId()) { // if its the message sent by me?
        // inflate right side layout.
    else 
        // inflate left side layout.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble getting this to work. What's strange is that I have 10 bookmarks
I'm having some strange trouble with pamie: http://pamie.sourceforge.net/ . I have written a script
I am having a bit of trouble grabbing some files that have a strange
I'm having some trouble figuring out the boost image library. I could not find
I'm in trouble here... I am having this strange output from a dynamic form
Having a strange issue with some C# code - the Getter method for a
I am having a strange DB2 issue when I run DBUnit tests. My DBUnit
I'm having a strange problem. I have to use GetPostBackEventRefence to force a Postback,
I'm having a strange problem in Visual Studio 2008 where my Pending Checkins window
I'm having a strange problem here... I have an ASP.NET 3.5 application that has

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.