怎样的android派emojicons图标点击时按钮? [英] android how to send emojicons icons when click on button?
问题描述
- 我想提出一个聊天aplication,在聊天过程中,我想送emojicons图标时,从对话框中选择,当点击发送按钮,它应该显示taht特定的图像。
2,当我正在点击发送按钮,它的发送用户ANDS显示,但问题是,我想上显示的名称。这个地方的形象,但它显示出我这个样子
像4.png或2.png。
我想DISPLY我所选择的图像,我do..i上午迷惑,请大家帮me.here是我的code
smilee.setOnClickListener(新OnClickListener()
{
@覆盖
公共无效的onClick(查看arg0中)
{ 如果(!popupWindow.isShowing())
{
popupWindow.setHeight((int)的(keyboardHeight)); 如果(isKeyBoardVisible){
emoticonsCover.setVisibility(LinearLayout.GONE);
}其他{
emoticonsCover.setVisibility(LinearLayout.VISIBLE);
}
popupWindow.showAtLocation(parentLayout,Gravity.BOTTOM,0,0); }其他{
popupWindow.dismiss();
} }});
send.setOnClickListener(新View.OnClickListener()
{
公共无效的onClick(查看视图)
{ 。字符串文本= mSendText.getText()的toString()修剪(); 跨区SP = mSendText.getText();
// chats.add(SP);
// content.setText();
mSendText.setCompoundDrawables(NULL,NULL,getResources()getDrawable(R.drawable.s1),NULL);
如果(commanInstance.checkInternetConn(getApplicationContext()))
{
如果(commanInstance.getConnection()。isConnected())
{
如果(text.length()!= 0)
{
Log.i(XMPPClient,发送文本[+文字+]到[+到+]); 聊天= NULL;
聊天= commanInstance.getConnection()getChatManager()createChat(于XMPPClient.this)。
chat_imageview.setEnabled(真); / *
*发送味精
* /
消息消息=新的Message(chat.getParticipant(),Message.Type.chat);
message.setThread(chat.getThreadID());
串messagePacketID = message.getPacketID();
//message.setProperty(\"Time,commanInstance.getCurrentTime());
message.setThread(commanInstance.getCurrentTime());
message.setBody(文本); MessageEventManager.addNotificationsRequests(消息,真的,真的,真的,真的);
尝试{
chat.sendMessage(消息);
sendCancelledNotification(到); }赶上(XMPPException E1){
e1.printStackTrace();
}
/ *
*在列表项加味精
* /
/ *
*插入到数据库
*
* /
数据库处理器分贝=新数据库处理器(getApplicationContext()); SimpleDateFormat的日期格式=新的SimpleDateFormat(YYYY-MM-DD HH:MM:SS);
日期日期=新的日期(); 的String [] =通宇to.split(@);
ItemTwoLine行为=新ItemTwoLine(getResources().getDrawable(R.drawable.ic_launcher),changeNameToCapital(getUserName())+\"#:#\"+text+\"#:#\"+\"Sent\",\"Me\"+\"#:#\"+commanInstance.getCurrentTime()+\"#:#\"+messagePacketID,true,getResources().getDrawable(R.drawable.check));
commanInstance.getCustomeList(listKeyValue)。新增(行为);
INT positionOfItem = commanInstance.getCustomeList(listKeyValue).indexOf(行为);
db.addContact(新Contact(getUserName(),toYou[0],changeNameToCapital(getUserName())+\"#:#\"+text+\"#:#\"+\"Sent\",\"Me\"+\"#:#\"+commanInstance.getCurrentTime()+\"#:#\"+messagePacketID,\"Sent\",\"Out\",\"garvage\",\"garvage\",String.valueOf(positionOfItem),dateFormat.format(date))); db.close();
/ *
*十个分量开放的对话屏幕列表
* / //字符串valForOpen = openCon [0] +#:#+文字; / *
*结束谈话开放屏幕列表并开始refersh列表
* / 如果(t)的
{
list.setAdapter(适配器); adapter.notifyDataSetChanged();
T = FALSE;
}
其他
{
adapter.notifyDataSetChanged();
}
mSendText.setText();
scrollMyListViewToBottom();
/ *
*设置报警
* /
// setAlarm(openCon [0]);
/ *
*设置报警结束
* /
}
}
}
}
});}
这是我的适配器类
味精=(TextView中)convertView.findViewById(R.id.Msg);
//Msg.setText(Html.fromHtml(nameAndText[1])); // TextView的textView2 =(的TextView)findViewById(R.id.TextView2);
SpannableStringBuilder SSB =新SpannableStringBuilder(nameAndText [1]);
//位图的笑脸= BitmapFactory.de codeResource(getResources(),R.drawable.emoticon); //ssb.setSpan(smiley,16,17,Spannable.SPAN_INCLUSIVE_INCLUSIVE);
Msg.setText(SSB,BufferType.SPANNABLE);
使用code可能有助于与文本发送emojisicon
textview.setText(getSmiledText(text.toString())); 公共Spannable getSmiledText(字符串文本){
SpannableStringBuilder建设者=新SpannableStringBuilder(文本);
如果(emoticons.size()大于0){
INT指数;
对于(指数= 0;指数 - LT; builder.length();指数++){
如果(Character.toString(builder.charAt(索引))等于(:)){
对于(Map.Entry的<字符串,整数>项:emoticons.entrySet()){
INT长度= entry.getKey()长()。
如果(索引+长度GT; builder.length())
继续;
如果(的ToString builder.subSequence(指数,指数+长度)()。等于(entry.getKey())){
builder.setSpan(新ImageSpan(的getContext(),entry.getValue()),指数,指数+长度,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
指数+ =长度 - 1;
打破;
}
}
}
}
}
返回建设者;
}
首先创建表情堆,试试这个。
私人的HashMap<字符串,整数>图释=新的HashMap<字符串,整数>();emoticons.put(:-),R.drawable.f01);
emoticons.put(:PR.drawable.f02);
emoticons.put(:D,R.drawable.f03);
- i am making an chatting aplication, in which during chatting , i want to send emojicons icons when selects from dialog and when click on send button, it should show taht particular image.
2.when i am clicking on send button,its sending to user ands showing.,but the problem is that i want to show image on the place of name.,but its showing me like this
like "4.png" or "2.png". i want to disply the image which i have selected.,what i do..i am confuse ,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 );
use this code may help to send the emojisicon with the text
textview.setText(getSmiledText(text.toString()));
public Spannable getSmiledText(String text) {
SpannableStringBuilder builder = new SpannableStringBuilder(text);
if (emoticons.size() > 0) {
int index;
for (index = 0; index < builder.length(); index++) {
if (Character.toString(builder.charAt(index)).equals(":")) {
for (Map.Entry<String, Integer> entry : emoticons.entrySet()) {
int length = entry.getKey().length();
if (index + length > builder.length())
continue;
if (builder.subSequence(index, index + length).toString().equals(entry.getKey())) {
builder.setSpan(new ImageSpan(getContext(), entry.getValue()), index, index + length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
index += length - 1;
break;
}
}
}
}
}
return builder;
}
first create the heap for the emoticons,try this.
private HashMap<String, Integer> emoticons = new HashMap<String, Integer>();
emoticons.put(":-)", R.drawable.f01);
emoticons.put(":P", R.drawable.f02);
emoticons.put(":D", R.drawable.f03);
这篇关于怎样的android派emojicons图标点击时按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!