首先描述下需求:
1、新增短信时,进来收件人是为空,显示一行文字(提醒)
2、从通讯录选择联系人后,回到短信编辑界面,收件栏显示一行,内容为“收件人:XXX、XXX、XXX、XXX.....”
3、当点击收件栏时,收件栏内容变化,变成可删除,最多显示四行,多余四行有上下滑动轮,不足四行,是几行显示几行
4、填写短信内容,即时计算短信条算,并有文本提示
下面是实现后效果图
下面终于到了代码实现块了,主要写一些主要用到的类,其他不太重要的就忽略写,读者自行补全。
首先是短信收件人是一个自定义的流布局,这个流布局不是本人写的,只是在上面加了些修改来满足自己的业务需求。
TagFlowLayout类
[java]view plaincopy
importjava.util.HashSet;
importjava.util.Iterator;
importjava.util.Set;
importcom.zhaonongzi.wnshhseller.R;
importandroid.content.Context;
importandroid.content.res.TypedArray;
importandroid.graphics.Rect;
importandroid.os.Bundle;
importandroid.os.Parcelable;
importandroid.text.TextUtils;
importandroid.util.AttributeSet;
importandroid.util.Log;
importandroid.view.MotionEvent;
importandroid.view.View;
/**
* 自定义tag 页面的整体页面
*
* 实现绑定数据,事件处理
* @author admin
*
*/
publicclassTagFlowLayoutextendsFlowLayoutimplements
TagAdapter.OnDataChangedListener {
privateTagAdapter mTagAdapter;
privatebooleanmAutoSelectEffect =true;
privateintmSelectedMax = -1;// -1为不限制数量
privatestaticfinalString TAG ="TagFlowLayout";
privateMotionEvent mMotionEvent;
privateSet mSelectedView =newHashSet();
publicTagFlowLayout(Context context, AttributeSet attrs,intdefStyle) {
super(context, attrs, defStyle);
TypedArray ta = context.obtainStyledAttributes(attrs,
R.styleable.TagFlowLayout);
mAutoSelectEffect = ta.getBoolean(R.styleable.TagFlowLayout_auto_select_effect,true);
mSelectedMax = ta.getInt(R.styleable.TagFlowLayout_max_select, -1);
ta.recycle();
if(mAutoSelectEffect) {
setClickable(true);
}
}
publicTagFlowLayout(Context context, AttributeSet attrs) {
this(context, attrs,0);
}
publicTagFlowLayout(Context context) {
this(context,null);
}
@Override
protectedvoidonMeasure(intwidthMeasureSpec,intheightMeasureSpec) {
intcCount = getChildCount();
for(inti =0; i < cCount; i++) {
TagView tagView = (TagView) getChildAt(i);
if(tagView.getVisibility() == View.GONE)
continue;
if(tagView.getTagView().getVisibility() == View.GONE) {
tagView.setVisibility(View.GONE);
}
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
publicinterfaceOnSelectListener {
voidonSelected(Set selectPosSet);
}
privateOnSelectListener mOnSelectListener;
publicvoidsetOnSelectListener(OnSelectListener onSelectListener) {
mOnSelectListener = onSelectListener;
if(mOnSelectListener !=null)
setClickable(true);
}
publicinterfaceOnTagClickListener {
booleanonTagClick(View view,intposition, FlowLayout parent);
}
privateOnTagClickListener mOnTagClickListener;
publicvoidsetOnTagClickListener(OnTagClickListener onTagClickListener) {
mOnTagClickListener = onTagClickListener;
if(onTagClickListener !=null)
setClickable(true);
}
publicvoidsetAdapter(TagAdapter adapter) {
// if (mTagAdapter == adapter)
// return;
mTagAdapter = adapter;
mTagAdapter.setOnDataChangedListener(this);
changeAdapter();
}
privatevoidchangeAdapter() {
removeAllViews();
TagAdapter adapter = mTagAdapter;
TagView tagViewContainer =null;
HashSet preCheckedList = mTagAdapter.getPreCheckedList();
for(inti =0; i < adapter.getCount(); i++) {
View tagView = adapter.getView(this, i, adapter.getItem(i));
tagViewContainer =newTagView(getContext());
// ViewGroup.MarginLayoutParams clp = (ViewGroup.MarginLayoutParams)
// tagView.getLayoutParams();
// ViewGroup.MarginLayoutParams lp = new
// ViewGroup.MarginLayoutParams(clp);
// lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
// lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
// lp.topMargin = clp.topMargin;
// lp.bottomMargin = clp.bottomMargin;
// lp.leftMargin = clp.leftMargin;
// lp.rightMargin = clp.rightMargin;
tagView.setDuplicateParentStateEnabled(true);
tagViewContainer.setLayoutParams(tagView.getLayoutParams());
tagViewContainer.addView(tagView);
addView(tagViewContainer);
if(preCheckedList.contains(i)) {
tagViewContainer.setChecked(true);
}
}
mSelectedView.addAll(preCheckedList);
}
@Override
publicbooleanonTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP) {
mMotionEvent = MotionEvent.obtain(event);
}
returnsuper.onTouchEvent(event);
}
@Override
publicbooleanperformClick() {
if(mMotionEvent ==null)
returnsuper.performClick();
intx = (int) mMotionEvent.getX();
inty = (int) mMotionEvent.getY();
mMotionEvent =null;
TagView child = findChild(x, y);
intpos = findPosByView(child);
if(child !=null) {
doSelect(child, pos);
if(mOnTagClickListener !=null) {
returnmOnTagClickListener.onTagClick(child.getTagView(), pos,
this);
}
}
returnsuper.performClick();
}
publicvoidsetMaxSelectCount(intcount) {
if(mSelectedView.size() > count) {
Log.w(TAG,"you has already select more than "+ count
+" views , so it will be clear .");
mSelectedView.clear();
}
mSelectedMax = count;
}
publicSet getSelectedList() {
returnnewHashSet(mSelectedView);
}
privatevoiddoSelect(TagView child,intposition) {
if(mAutoSelectEffect) {
if(!child.isChecked()) {
// 处理max_select=1的情况
if(mSelectedMax ==1&& mSelectedView.size() ==1) {
Iterator iterator = mSelectedView.iterator();
Integer preIndex = iterator.next();
TagView pre = (TagView) getChildAt(preIndex);
pre.setChecked(false);
child.setChecked(true);
mSelectedView.remove(preIndex);
mSelectedView.add(position);
}else{
if(mSelectedMax >0
&& mSelectedView.size() >= mSelectedMax)
return;
child.setChecked(true);
mSelectedView.add(position);
}
}else{
child.setChecked(false);
mSelectedView.remove(position);
}
if(mOnSelectListener !=null) {
mOnSelectListener
.onSelected(newHashSet(mSelectedView));
}
}
}
privatestaticfinalString KEY_CHOOSE_POS ="key_choose_pos";
privatestaticfinalString KEY_DEFAULT ="key_default";
@Override
protectedParcelable onSaveInstanceState() {
Bundle bundle =newBundle();
bundle.putParcelable(KEY_DEFAULT,super.onSaveInstanceState());
String selectPos ="";
if(mSelectedView.size() >0) {
for(intkey : mSelectedView) {
selectPos += key +"|";
}
selectPos = selectPos.substring(0, selectPos.length() -1);
}
bundle.putString(KEY_CHOOSE_POS, selectPos);
returnbundle;
}
@Override
protectedvoidonRestoreInstanceState(Parcelable state) {
if(stateinstanceofBundle) {
Bundle bundle = (Bundle) state;
String mSelectPos = bundle.getString(KEY_CHOOSE_POS);
if(!TextUtils.isEmpty(mSelectPos)) {
String[] split = mSelectPos.split("\\|");
for(String pos : split) {
intindex = Integer.parseInt(pos);
mSelectedView.add(index);
TagView tagView = (TagView) getChildAt(index);
tagView.setChecked(true);
}
}
super.onRestoreInstanceState(bundle.getParcelable(KEY_DEFAULT));
return;
}
super.onRestoreInstanceState(state);
}
privateintfindPosByView(View child) {
finalintcCount = getChildCount();
for(inti =0; i < cCount; i++) {
View v = getChildAt(i);
if(v == child)
returni;
}
return-1;
}
privateTagView findChild(intx,inty) {
finalintcCount = getChildCount();
for(inti =0; i < cCount; i++) {
TagView v = (TagView) getChildAt(i);
if(v.getVisibility() == View.GONE)
continue;
Rect outRect =newRect();
v.getHitRect(outRect);
if(outRect.contains(x, y)) {
returnv;
}
}
returnnull;
}
@Override
publicvoidonChanged() {
changeAdapter();
}
}
FlowLayout类
[java]view plaincopy
importandroid.content.Context;
importandroid.util.AttributeSet;
importandroid.util.Log;
importandroid.view.View;
importandroid.view.ViewGroup;
importjava.util.ArrayList;
importjava.util.List;
importcom.zhaonongzi.wnshhseller.activity.customer.AddMessageActivity;
importcom.zhaonongzi.wnshhseller.utils.GlobalMemoryCache;
/**
* Tag 页面布局基类 主要实现测量子view,绘制view
*
* @author admin
*
*/
publicclassFlowLayoutextendsViewGroup {
protectedList> mAllViews =newArrayList>();
protectedList mLineHeight =newArrayList();
privateintlines, counts, lastItem;// 限制显示多少行
privatebooleanisShow;// 是否需要在最后显示省略号
privateLastListerInterface lastListerInterface =null;
privateintihegth;
publicFlowLayout(Context context, AttributeSet attrs,intdefStyle) {
super(context, attrs, defStyle);
}
publicFlowLayout(Context context, AttributeSet attrs) {
this(context, attrs,0);
}
publicFlowLayout(Context context) {
this(context,null);
}
publicvoidsetLines(intline) {
this.lines = line;
}
publicintgetLastItem() {
Log.e("lastItem", lastItem +"");
returnlastItem;
}
@Override
protectedvoidonMeasure(intwidthMeasureSpec,intheightMeasureSpec) {
intsizeWidth = MeasureSpec.getSize(widthMeasureSpec);
intmodeWidth = MeasureSpec.getMode(widthMeasureSpec);
intsizeHeight = MeasureSpec.getSize(heightMeasureSpec);
intmodeHeight = MeasureSpec.getMode(heightMeasureSpec);
// wrap_content
intwidth =0;
intheight =0;
intlineWidth =0;
intlineHeight =0;
intchildHeight1 =0;
intcCount = getChildCount();
for(inti =0; i < cCount; i++) {
View child = getChildAt(i);
if(child.getVisibility() == View.GONE) {
if(i == cCount -1) {
width = Math.max(lineWidth, width);
height += lineHeight;
}
continue;
}
measureChild(child, widthMeasureSpec, heightMeasureSpec);
MarginLayoutParams lp = (MarginLayoutParams) child
.getLayoutParams();
intchildWidth = child.getMeasuredWidth() + lp.leftMargin
+ lp.rightMargin;
intchildHeight = child.getMeasuredHeight() + lp.topMargin
+ lp.bottomMargin;
childHeight1 = childHeight;
if(lineWidth + childWidth > sizeWidth - getPaddingLeft()
- getPaddingRight()) {
width = Math.max(width, lineWidth);
lineWidth = childWidth;
height += lineHeight;
lineHeight = childHeight;
}else{
lineWidth += childWidth;
lineHeight = Math.max(lineHeight, childHeight);
}
if(i == cCount -1) {
width = Math.max(lineWidth, width);
height += lineHeight;
}
if(lastItem ==0&& height == (3* childHeight)) {
lastItem = i -1;
if(lastItem >0&&null!= lastListerInterface) {
lastListerInterface.getLastItem(lastItem);
}
}
// Log.e("lastItem", lastItem + "");
}
height = (height <= (lines * childHeight1)) ? height
: (lines * childHeight1);
ihegth = height;
AddMessageActivity.iheight = childHeight1;
setMeasuredDimension(
//
modeWidth == MeasureSpec.EXACTLY ? sizeWidth : width
+ getPaddingLeft() + getPaddingRight(),
modeHeight == MeasureSpec.EXACTLY ? sizeHeight : height
+ getPaddingTop() + getPaddingBottom()//
);
}
publicintgetHeigth() {
returnihegth;
}
@Override
protectedvoidonLayout(booleanchanged,intl,intt,intr,intb) {
mAllViews.clear();
mLineHeight.clear();
intwidth = getWidth();
intlineWidth =0;
intlineHeight =0;
List lineViews =newArrayList();
intcCount = getChildCount();
for(inti =0; i < cCount; i++) {
View child = getChildAt(i);
if(child.getVisibility() == View.GONE)
continue;
MarginLayoutParams lp = (MarginLayoutParams) child
.getLayoutParams();
intchildWidth = child.getMeasuredWidth();
intchildHeight = child.getMeasuredHeight();
if(childWidth + lineWidth + lp.leftMargin + lp.rightMargin > width
- getPaddingLeft() - getPaddingRight()) {
if(mAllViews.size() < lines) {
mLineHeight.add(lineHeight);
mAllViews.add(lineViews);
lineWidth =0;
lineHeight = childHeight + lp.topMargin + lp.bottomMargin;
lineViews =newArrayList();
}
}
lineWidth += childWidth + lp.leftMargin + lp.rightMargin;
lineHeight = Math.max(lineHeight, childHeight + lp.topMargin
+ lp.bottomMargin);
lineViews.add(child);
}
mLineHeight.add(lineHeight);
mAllViews.add(lineViews);
intleft = getPaddingLeft();
inttop = getPaddingTop();
intlineNum = mAllViews.size();
AddMessageActivity.ilines = lineNum;
if(lines >0) {
lineNum = lineNum > lines ? lines : lineNum;
}
for(inti =0; i < lineNum; i++) {
lineViews = mAllViews.get(i);
lineHeight = mLineHeight.get(i);
for(intj =0; j < lineViews.size(); j++) {
View child = lineViews.get(j);
if(child.getVisibility() == View.GONE) {
continue;
}
MarginLayoutParams lp = (MarginLayoutParams) child
.getLayoutParams();
intlc = left + lp.leftMargin;
inttc = top + lp.topMargin;
intrc = lc + child.getMeasuredWidth();
intbc = tc + child.getMeasuredHeight();
child.layout(lc, tc, rc, bc);
left += child.getMeasuredWidth() + lp.leftMargin
+ lp.rightMargin;
}
left = getPaddingLeft();
top += lineHeight;
}
if((boolean) GlobalMemoryCache.getInstance().get("addMessage")) {
AddMessageActivity.tfl_add_message_labellay
.setVisibility(View.GONE);
AddMessageActivity.scr_add_message_labellay
.setVisibility(View.GONE);
}
}
@Override
publicLayoutParams generateLayoutParams(AttributeSet attrs) {
returnnewMarginLayoutParams(getContext(), attrs);
}
@Override
protectedLayoutParams generateDefaultLayoutParams() {
returnnewMarginLayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
}
@Override
protectedLayoutParams generateLayoutParams(LayoutParams p) {
returnnewMarginLayoutParams(p);
}
publicinterfaceLastListerInterface {
publicvoidgetLastItem(intlastItem);
}
publicvoidsetLastListener(LastListerInterface lastListerInterface) {
this.lastListerInterface = lastListerInterface;
}
}
TagAdapter类
[java]view plaincopy
importjava.util.ArrayList;
importjava.util.Arrays;
importjava.util.HashSet;
importjava.util.List;
importandroid.view.View;
/**
* tag 布局适配器
* @author admin
*
* @param
*/
publicabstractclassTagAdapter
{
privateList mTagDatas;
privateOnDataChangedListener mOnDataChangedListener;
privateHashSet mCheckedPosList =newHashSet();
publicTagAdapter(List datas)
{
mTagDatas = datas;
}
publicTagAdapter(T[] datas)
{
mTagDatas =newArrayList(Arrays.asList(datas));
}
staticinterfaceOnDataChangedListener
{
voidonChanged();
}
voidsetOnDataChangedListener(OnDataChangedListener listener)
{
mOnDataChangedListener = listener;
}
publicvoidsetSelectedList(int... pos)
{
for(inti =0; i < pos.length; i++)
mCheckedPosList.add(pos[i]);
notifyDataChanged();
}
HashSet getPreCheckedList()
{
returnmCheckedPosList;
}
publicintgetCount()
{
returnmTagDatas ==null?0: mTagDatas.size();
}
publicvoidnotifyDataChanged()
{
mOnDataChangedListener.onChanged();
}
publicT getItem(intposition)
{
returnmTagDatas.get(position);
}
publicabstractView getView(FlowLayout parent,intposition, T t);
}
TagView类
[java]view plaincopy
importandroid.content.Context;
importandroid.view.View;
importandroid.widget.Checkable;
importandroid.widget.FrameLayout;
/**
* 单个Tag 的自定义布局
*
* @author admin
*
*/
publicclassTagViewextendsFrameLayoutimplementsCheckable
{
privatebooleanisChecked;
privatestaticfinalint[] CHECK_STATE =newint[]{android.R.attr.state_checked};
publicTagView(Context context)
{
super(context);
}
publicView getTagView()
{
returngetChildAt(0);
}
@Override
publicint[] onCreateDrawableState(intextraSpace)
{
int[] states =super.onCreateDrawableState(extraSpace +1);
if(isChecked())
{
mergeDrawableStates(states, CHECK_STATE);
}
returnstates;
}
/**
* Change the checked state of the view
*
* @param checked The new checked state
*/
@Override
publicvoidsetChecked(booleanchecked)
{
if(this.isChecked != checked)
{
this.isChecked = checked;
refreshDrawableState();
}
}
/**
* @return The current checked state of the view
*/
@Override
publicbooleanisChecked()
{
returnisChecked;
}
/**
* Change the checked state of the view to the inverse of its current state
*/
@Override
publicvoidtoggle()
{
setChecked(!isChecked);
}
}
上面是用到TagFlowLayout这个自定义控件需要的类。
下面给出短信编辑的布局xml文件
[html]view plaincopy
xmlns:tag="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f5f5f5"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
android:id="@+id/message_mass_top"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|top"/>
android:id="@+id/linear_edit_message_add_receiver"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/message_mass_top"
android:orientation="horizontal">
android:id="@+id/txt_add_message_customer_declare"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:gravity="center"
android:paddingLeft="15dp"
android:text="收信人"
android:textColor="@color/black"
android:visibility="gone"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1">
android:id="@+id/txt_add_message_add_customer_btn"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="left|center"
android:paddingLeft="15dp"
android:singleLine="true"
android:text="点击添加收信客户"
android:textColor="@color/gray"/>
android:id="@+id/scr_add_message_labellay"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:visibility="gone">
android:id="@+id/tfl_add_message_labellay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ac_include"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:visibility="gone"
tag:max_select="-1"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="15dp"
android:layout_gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp">
android:id="@+id/img_add_message_add_customer"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:src="@drawable/username"/>
android:id="@+id/txt_add_message_customer_counts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="@color/black"
android:text="0"/>
android:id="@+id/line_1"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="@+id/linear_edit_message_add_receiver"
android:layout_marginBottom="2dp"
android:layout_marginTop="2dp"
android:background="#A0A0A0"/>
android:id="@+id/edittext_add_message_add_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/line_1"
android:background="@drawable/select_white_bg"
android:minHeight="80dp"
android:padding="15dp"
android:maxLength="650"
android:scrollbars="vertical"
android:maxHeight="200dp"
android:textColor="@color/black"/>
android:id="@+id/txt_add_message_add_content_num"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edittext_add_message_add_content"
android:layout_toLeftOf="@+id/txt_add_message_add_content_word"
android:paddingTop="10dp"
android:text="0"
android:textColor="@color/orange_title"/>
android:id="@+id/txt_add_message_add_content_word"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/edittext_add_message_add_content"
android:paddingRight="15dp"
android:paddingTop="10dp"
android:text=""
android:textColor="@color/gray"/>
实例化一个收件人adapter
[java]view plaincopy
adapter =newTagAdapter(meBean.getReceiver()) {
finalLayoutInflater mInflater = LayoutInflater
.from(AddMessageActivity.this);
@SuppressLint("NewApi")
@Override
publicView getView(FlowLayout parent,finalintposition,
finalString s) {
finalTextView tv = (TextView) mInflater.inflate(
R.layout.item_label_tv_medium,
tfl_add_message_labellay,false);
SpannableStringBuilder sp1 =newSpannableStringBuilder(
s);// 姓名
SpannableStringBuilder sp2 =newSpannableStringBuilder(
"x");// 删除
sp1.setSpan(
newForegroundColorSpan(Color
.rgb(102,102,102)),0, s.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
sp2.setSpan(
newForegroundColorSpan(Color.rgb(255,0,0)),
0,"X".length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
SpannableStringBuilder sp =newSpannableStringBuilder();//
sp.append(sp1).append(sp2);
if(position ==0) {
tv.setText(s);
tv.setTextColor(android.graphics.Color
.parseColor("#666666"));
}else{
tv.setText(sp);
tv.setTextSize(16);
tv.setBackgroundResource(R.drawable.selector_contacts_gray_btn);
}
tv.setOnClickListener(newView.OnClickListener() {
@Override
publicvoidonClick(View v) {
// 跳页面带值
if(position !=0) {
meBean.getReceiver().remove(position);
handler.sendEmptyMessage(1);
}
}
});
returntv;
}
};
计算短信条数方法:
[java]view plaincopy
/**
* 计算短信内容条算
*
* @param wordNum
* @return
*/
publicintgetSMSCounts(intwordNum) {
intcounts;
if(wordNum <=63)
counts =1;
elseif(wordNum <=127)
counts =2;
else{
counts = (wordNum -127) %67==0? ((wordNum -127) /67+2)
: ((wordNum +7) /67+1);
}
returncounts;
}
监听编辑文本框来提示短信条数和字数:
[java]view plaincopy
edittext_edit_message_add_content
.addTextChangedListener(newTextWatcher() {
@Override
publicvoidonTextChanged(CharSequence s,intstart,
intbefore,intcount) {
// TODO Auto-generated method stub
}
@Override
publicvoidbeforeTextChanged(CharSequence s,intstart,
intcount,intafter) {
}
@Override
publicvoidafterTextChanged(Editable s) {
if(getSMSCounts(edittext_edit_message_add_content
.getText().toString().trim().length()) ==1) {
intc =63- edittext_edit_message_add_content
.getText().toString().trim().length();
txt_add_message_add_content_num.setText(c +"");
txt_add_message_add_content_word.setText("");
}elseif(getSMSCounts(edittext_edit_message_add_content
.getText().toString().trim().length()) ==2) {
intc =127- edittext_edit_message_add_content
.getText().toString().trim().length();
txt_add_message_add_content_num.setText(c +"");
txt_add_message_add_content_word.setText("(2)");
}elseif(getSMSCounts(edittext_edit_message_add_content
.getText().toString().trim().length()) >2) {
intc = getSMSCounts(edittext_edit_message_add_content
.getText().toString().trim().length())
*67
-7
- edittext_edit_message_add_content
.getText().toString().trim()
.length();
txt_add_message_add_content_num.setText(c +"");
txt_add_message_add_content_word
.setText("("
+ getSMSCounts(edittext_edit_message_add_content
.getText().toString()
.trim().length()) +")");
}
}
});
接收删除后的handler处理:
[java]view plaincopy
privateHandler handler =newHandler() {
publicvoidhandleMessage(android.os.Message msg) {
if(msg.what ==1) {
tfl_add_message_labellay.onChanged();
txt_add_message_customer_counts.setText((meBean.getReceiver()
.size() -1) +"");
}
};
};
上面已经把关键的代码都贴出来了,其实最重要的 地方是按流布局去显示收件人,原生的是没有限制显示行数,也没有处理多行后的滑动轮,头疼的地方是去计算显示高度并动态设置scrollview的高地。坑都已经踩过了,但是这个代码的效率不是很高,有待继续完善,或者有什么好的建议也可以给我提。