类似MIUI原生短信编辑功能

首先描述下需求:

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的高地。坑都已经踩过了,但是这个代码的效率不是很高,有待继续完善,或者有什么好的建议也可以给我提。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,736评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,167评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,442评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,902评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,302评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,573评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,847评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,562评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,260评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,531评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,021评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,367评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,016评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,068评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,827评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,610评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,514评论 2 269

推荐阅读更多精彩内容