1.I am making an chatting application, in which during chatting, I want to send emoticons icons when selects from the dialog and then click on send button, it should show that particular image.
2.when I am clicking on send button, it's sending to user and shows, but the problem is that I want to show the image on the place of a name, but it's showing me like this
like "4.png" or "2.png". I want to display the image which I have selected. What should I do? I am confused, please help me.here is my code
smilee.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
if (!popupWindow.isShowing())
{
popupWindow.setHeight((int) (keyboardHeight));
if (isKeyBoardVisible) {
emoticonsCover.setVisibility(LinearLayout.GONE);
} else {
emoticonsCover.setVisibility(LinearLayout.VISIBLE);
}
popupWindow.showAtLocation(parentLayout, Gravity.BOTTOM, 0, 0);
} else {
popupWindow.dismiss();
}
}});
send.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
String text = mSendText.getText().toString().trim();
Spanned sp = mSendText.getText();
//chats.add(sp);
//content.setText("");
mSendText.setCompoundDrawables(null, null, getResources().getDrawable(R.drawable.s1), null);
if(commanInstance.checkInternetConn(getApplicationContext()))
{
if(commanInstance.getConnection().isConnected())
{
if(text.length()!=0)
{
Log.i("XMPPClient", "Sending text [" + text + "] to [" + to + "]");
Chat chat = null;
chat = commanInstance.getConnection().getChatManager().createChat(to, XMPPClient.this);
chat_imageview.setEnabled(true);
/*
* send msg
*/
Message message = new Message(chat.getParticipant(), Message.Type.chat);
message.setThread(chat.getThreadID());
String messagePacketID=message.getPacketID();
//message.setProperty("Time", commanInstance.getCurrentTime());
message.setThread(commanInstance.getCurrentTime());
message.setBody(text);
MessageEventManager.addNotificationsRequests(message, true, true, true, true);
try {
chat.sendMessage(message);
sendCancelledNotification(to);
} catch (XMPPException e1) {
e1.printStackTrace();
}
/*
* add msg in list item
*/
/*
* insert into database
*
*/
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String[] toYou=to.split("@");
ItemTwoLine act=new ItemTwoLine(getResources().getDrawable(R.drawable.ic_launcher),changeNameToCapital(getUserName())+"#:#"+text+"#:#"+"Sent","Me"+"#:#"+commanInstance.getCurrentTime()+"#:#"+messagePacketID,true,getResources().getDrawable(R.drawable.check));
commanInstance.getCustomeList(listKeyValue).add(act);
int positionOfItem=commanInstance.getCustomeList(listKeyValue).indexOf(act);
db.addContact(new Contact(getUserName(),toYou[0],changeNameToCapital(getUserName())+"#:#"+text+"#:#"+"Sent","Me"+"#:#"+commanInstance.getCurrentTime()+"#:#"+messagePacketID,"Sent","Out","garvage","garvage",String.valueOf(positionOfItem),dateFormat.format(date)));
db.close();
/*
* Mantain open conversation screen list
*/
// String valForOpen=openCon[0]+"#:#"+text;
/*
* End open conversation screen list and start refersh list
*/
if(t)
{
list.setAdapter(adapter);
adapter.notifyDataSetChanged();
t=false;
}
else
{
adapter.notifyDataSetChanged();
}
mSendText.setText("");
scrollMyListViewToBottom();
/*
* set alarm
*/
//setAlarm(openCon[0]);
/*
* set alarm end
*/
}
}
}
}
});
}
Here is my adapter class
Msg = (TextView) convertView.findViewById(R.id.Msg);
//Msg.setText(Html.fromHtml(nameAndText[1] ));
// TextView textView2 = (TextView)findViewById( R.id.TextView2 );
SpannableStringBuilder ssb = new SpannableStringBuilder(nameAndText[1]);
//Bitmap smiley = BitmapFactory.decodeResource( getResources(), R.drawable.emoticon );
//ssb.setSpan(smiley, 16, 17, Spannable.SPAN_INCLUSIVE_INCLUSIVE );
Msg.setText( ssb, BufferType.SPANNABLE );
You can use this library.
https://github.com/rockerhieu/emojicon
It has custom text views and controls which are capable to displaying the smileys and also handles converting them to unicode.
I used this with our chat application and it worked like a charm, even saving them in database is very easy.
use this code may help to send the emojisicon with the text
first create the heap for the emoticons,try this.