how to set bubble images to background of textview in android programatically?
msgList = (ListView)findVi开发者_StackOverflow中文版ewById(R.id.msgList);
receivedMessages = new ArrayAdapter<String>(this, R.layout.message);
msgList.setAdapter(receivedMessages);
msg = (EditText)findViewById(R.id.msg);
msg.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if ((event.getAction() == KeyEvent.ACTION_UP) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
postMessage();
return true;
}
return false;
}
});
private void postMessage()
{
String theNewMessage = msg.getText().toString();
try{
myThread.sendMessage(theNewMessage);
}catch(Exception e){
Log.e(TAG,"Cannot send message"+e.getMessage());
}
receivedMessages.add(theNewMessage+":Me");
msg.setText("");
//receivedMessages.getContext().getString(sendmsg);
}
I want to set background bubble image to string result means theNewmessage. Where I get the my result.bubble image get automatic size according to its character size length.
in you R.layout.message set the layout's background to the bubble image you want to use. If you use a nine patch image, it will size itself.
http://developer.android.com/guide/developing/tools/draw9patch.html
http://www.higherpass.com/Android/Tutorials/Android-9-Patch-Scaled-Png-Image-Guide/
精彩评论