㈠ 安卓系统 智能手机 一条短信字数的最大限制是多少
您好,一条普通短信的长度为140个字符,大约70个汉字左右,但阿拉伯数字、标点符号也占2个字符,因此,一条短信有时达不到70个汉字,目前市场大多数手机支持长短信的自动合并功能,能将收到的超长短信自动合并为一条显示,但在网络传送的过程中会发送多条短信,且会计多条费用。
安徽电信竭诚为您服务 www.ah.189.cn
㈡ android限定输入的数字为1至12
为Edittext设置一个InputFilter
public class EditInputFilter implements InputFilter{
/**
* source 新输入的字符串
* start 新输入的字符串起始下标,一般为0
* end 新输入的字符串终点下标,一般为source长度-1
* dest 输入之前文本框内容
* dstart 原内容起始坐标,一般为0
* dend 原内容终点坐标,一般为dest长度-1
*/
@Override
public CharSequence filter(CharSequence src, int start, int end,
Spanned dest, int dstart, int dend) {
if(!dest.equals("")&&Integer.values(dest)*10+Integer.values(source)>12){
return dest.subSequence(dstart, dend);
}
return dest.subSequence(dstart, dend) +src.toString();
}
}
InputFilter[] filters = { new EditInputFilter() };
edit.setFilters(filters);
记得在XML文件了设置Edittext只能输入数字,长度最大2
㈢ Android 系统搜索框 如何限制输入字数长度
android 搜索框就是一个EditText输入控件,或者是EditText的子类
长度限制方式有以下几种:
方法一:
在 xml 文件中设置文本编辑框属性作字符数限制
如:android:maxLength="10" 即限制最大输入字符个数为10
方法二:
在代码中使用InputFilter 进行过滤
//editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)}); 即限定最大输入字符数为20
示例代码如下:
java">{
/**.*/
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditTexteditText=(EditText)findViewById(R.id.entry);
editText.setFilters(newInputFilter[]{newInputFilter.LengthFilter(20)});
}
}
方法三:
利用 TextWatcher 进行限制,TextWatcher是注册一个内存输入的改变事件,当你的输入框输入字符和删除字符都会触发
实现代码如下:
packagecie.textEdit;
importandroid.text.Editable;
importandroid.text.Selection;
importandroid.text.TextWatcher;
importandroid.widget.EditText;
/*
*监听输入内容是否超出最大长度,并设置光标位置
**/
{
privateintmaxLen=0;
privateEditTexteditText=null;
publicMaxLengthWatcher(intmaxLen,EditTexteditText){
this.maxLen=maxLen;
this.editText=editText;
}
publicvoidafterTextChanged(Editablearg0){
//TODOAuto-generatedmethodstub
}
publicvoidbeforeTextChanged(CharSequencearg0,intarg1,intarg2,
intarg3){
//TODOAuto-generatedmethodstub
}
publicvoidonTextChanged(CharSequencearg0,intarg1,intarg2,intarg3){
//TODOAuto-generatedmethodstub
Editableeditable=editText.getText();
intlen=editable.length();
if(len>maxLen)
{
intselEndIndex=Selection.getSelectionEnd(editable);
Stringstr=editable.toString();
//截取新字符串
StringnewStr=str.substring(0,maxLen);
editText.setText(newStr);
editable=editText.getText();
//新字符串的长度
intnewLen=editable.length();
//旧光标位置超过字符串长度
if(selEndIndex>newLen)
{
selEndIndex=editable.length();
}
//设置新光标所在的位置
Selection.setSelection(editable,selEndIndex);
}
}
}
有关EditText 即Android输入框的更多用法,建议查看官网API文档
㈣ android edittext 控制输入多少个字符
可以对输入长度进行设置就可以了
1、第一种方式是通过EditText的inputType来实现,可以通过xml或者java文件来设置。假如我要设置为显示密码的形式,可以像下面这样设置:
在xml中, android:inputType="textPassword"
在java文件中,可以用 myEditText.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
当然,还有更多的其他属性用来进行输入设置。
2、第二种是通过android:digits 属性来设置,这种方式可以指出要显示的字符,比如我要限制只显示数字,可以这样:
android:digits="0123456789"
还有更多可以http://blog.csdn.net/goodlixueyong/article/details/40655317
㈤ android 中如何限制 EditText 最大输入字符数
方法一:
在 xml 文件中设置文本编辑框属性作字符数限制
如:android:maxLength="10" 即限制最大输入字符个数为10
方法二:
在代码中使用InputFilter 进行过滤
//editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)}); 即限定最大输入字符数为20
[java] view plainprint?
01.public class TextEditActivity extends Activity {
02. /** Called when the activity is first created. */
03. @Override
04. public void onCreate(Bundle savedInstanceState) {
05. super.onCreate(savedInstanceState);
06. setContentView(R.layout.main);
07.
08. EditText editText = (EditText)findViewById(R.id.entry);
09. editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
10. }
11.}
public class TextEditActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText editText = (EditText)findViewById(R.id.entry);
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
}
}
方法三:
利用 TextWatcher 进行监听
[java] view plainprint?
01.package cie.textEdit;
02.
03.import android.text.Editable;
04.import android.text.Selection;
05.import android.text.TextWatcher;
06.import android.widget.EditText;
07.
08./*
09. * 监听输入内容是否超出最大长度,并设置光标位置
10. * */
11.public class MaxLengthWatcher implements TextWatcher {
12.
13. private int maxLen = 0;
14. private EditText editText = null;
15.
16.
17. public MaxLengthWatcher(int maxLen, EditText editText) {
18. this.maxLen = maxLen;
19. this.editText = editText;
20. }
21.
22. public void afterTextChanged(Editable arg0) {
23. // TODO Auto-generated method stub
24.
25. }
26.
27. public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
28. int arg3) {
29. // TODO Auto-generated method stub
30.
31. }
32.
33. public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
34. // TODO Auto-generated method stub
35. Editable editable = editText.getText();
36. int len = editable.length();
37.
38. if(len > maxLen)
39. {
40. int selEndIndex = Selection.getSelectionEnd(editable);
41. String str = editable.toString();
42. //截取新字符串
43. String newStr = str.substring(0,maxLen);
44. editText.setText(newStr);
45. editable = editText.getText();
46.
47. //新字符串的长度
48. int newLen = editable.length();
49. //旧光标位置超过字符串长度
50. if(selEndIndex > newLen)
51. {
52. selEndIndex = editable.length();
53. }
54. //设置新光标所在的位置
55. Selection.setSelection(editable, selEndIndex);
56.
57. }
58. }
59.
60.}
package cie.textEdit;
import android.text.Editable;
import android.text.Selection;
import android.text.TextWatcher;
import android.widget.EditText;
/*
* 监听输入内容是否超出最大长度,并设置光标位置
* */
public class MaxLengthWatcher implements TextWatcher {
private int maxLen = 0;
private EditText editText = null;
public MaxLengthWatcher(int maxLen, EditText editText) {
this.maxLen = maxLen;
this.editText = editText;
}
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
Editable editable = editText.getText();
int len = editable.length();
if(len > maxLen)
{
int selEndIndex = Selection.getSelectionEnd(editable);
String str = editable.toString();
//截取新字符串
String newStr = str.substring(0,maxLen);
editText.setText(newStr);
editable = editText.getText();
//新字符串的长度
int newLen = editable.length();
//旧光标位置超过字符串长度
if(selEndIndex > newLen)
{
selEndIndex = editable.length();
}
//设置新光标所在的位置
Selection.setSelection(editable, selEndIndex);
}
}
}
对应的 activity 部分的调用为:
[java] view plainprint?
01.package cie.textEdit;
02.
03.import android.app.Activity;
04.import android.os.Bundle;
05.import android.text.InputFilter;
06.import android.widget.EditText;
07.
08.public class TextEditActivity extends Activity {
09. /** Called when the activity is first created. */
10. @Override
11. public void onCreate(Bundle savedInstanceState) {
12. super.onCreate(savedInstanceState);
13. setContentView(R.layout.main);
14.
15. EditText editText = (EditText) findViewById(R.id.entry);
16. editText.addTextChangedListener(new MaxLengthWatcher(10, editText));
17.
18. }
19.}
package cie.textEdit;
import android.app.Activity;
import android.os.Bundle;
import android.text.InputFilter;
import android.widget.EditText;
public class TextEditActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText editText = (EditText) findViewById(R.id.entry);
editText.addTextChangedListener(new MaxLengthWatcher(10, editText));
}
}
限制输入字符数为10个
main.xml 文件
[html] view plainprint?
01.<?xml version="1.0" encoding="utf-8"?>
02.<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
03. android:layout_width="fill_parent"
04. android:layout_height="fill_parent">
05. <TextView
06. android:id="@+id/label"
07. android:layout_width="fill_parent"
08. android:layout_height="wrap_content"
09. android:text="Type here:"/>
10. <EditText
11. android:id="@+id/entry"
12. android:singleLine="true"
13. android:layout_width="fill_parent"
14. android:layout_height="wrap_content"
15. android:background="@android:drawable/editbox_background"
16. android:layout_below="@id/label"/>
17. <Button
18. android:id="@+id/ok"
19. android:layout_width="wrap_content"
20. android:layout_height="wrap_content"
21. android:layout_below="@id/entry"
22. android:layout_alignParentRight="true"
23. android:layout_marginLeft="10dip"
24. android:text="OK" />
25. <Button
26. android:layout_width="wrap_content"
27. android:layout_height="wrap_content"
28. android:layout_toLeftOf="@id/ok"
29. android:layout_alignTop="@id/ok"
30. android:text="Cancel" />
31.</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type here:"/>
<EditText
android:id="@+id/entry"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label"/>
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="OK" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="Cancel" />
</RelativeLayout>
㈥ android log.i()最多可以显示多少字符
实际测试过,4070个字符。
StringBuilder a = new StringBuilder("");
for (int i = 0; i < 1000; i++) {
a.append("abcdefghijklmnopqrstuvwxyz");
}
Log.i("test", a.toString());
结果显示了156遍a-z,最后显示到n就没有了。
㈦ android 将json生成string时候,是否有长度限制
前台接受到的json对象本身就是一个字符串,只不过比一般的字符串多了一些格式,便于拆分出各个属性的信息
㈧ android怎么edittext汉字限制
方法一:
在 xml 文件中设置文本编辑框属性作字符数限制
如:android:maxLength="10" 即限制最大输入字符个数为10
方法二:
在代码中使用InputFilter 进行过滤
//editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)}); 即限定最大输入字符数为20
[java] view plainprint?
01.public class TextEditActivity extends Activity {
02. /** Called when the activity is first created. */
03. @Override
04. public void onCreate(Bundle savedInstanceState) {
05. super.onCreate(savedInstanceState);
06. setContentView(R.layout.main);
07.
08. EditText editText = (EditText)findViewById(R.id.entry);
09. editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
10. }
11.}
public class TextEditActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText editText = (EditText)findViewById(R.id.entry);
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20)});
}
}
方法三:
利用 TextWatcher 进行监听
[java] view plainprint?
01.package cie.textEdit;
02.
03.import android.text.Editable;
04.import android.text.Selection;
05.import android.text.TextWatcher;
06.import android.widget.EditText;
07.
08./*
09. * 监听输入内容是否超出最大长度,并设置光标位置
10. * */
11.public class MaxLengthWatcher implements TextWatcher {
12.
13. private int maxLen = 0;
14. private EditText editText = null;
15.
16.
17. public MaxLengthWatcher(int maxLen, EditText editText) {
18. this.maxLen = maxLen;
19. this.editText = editText;
20. }
21.
22. public void afterTextChanged(Editable arg0) {
23. // TODO Auto-generated method stub
24.
25. }
26.
27. public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
28. int arg3) {
29. // TODO Auto-generated method stub
30.
31. }
32.
33. public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
34. // TODO Auto-generated method stub
35. Editable editable = editText.getText();
36. int len = editable.length();
37.
38. if(len > maxLen)
39. {
40. int selEndIndex = Selection.getSelectionEnd(editable);
41. String str = editable.toString();
42. //截取新字符串
43. String newStr = str.substring(0,maxLen);
44. editText.setText(newStr);
45. editable = editText.getText();
46.
47. //新字符串的长度
48. int newLen = editable.length();
49. //旧光标位置超过字符串长度
50. if(selEndIndex > newLen)
51. {
52. selEndIndex = editable.length();
53. }
54. //设置新光标所在的位置
55. Selection.setSelection(editable, selEndIndex);
56.
57. }
58. }
59.
60.}
package cie.textEdit;
import android.text.Editable;
import android.text.Selection;
import android.text.TextWatcher;
import android.widget.EditText;
/*
* 监听输入内容是否超出最大长度,并设置光标位置
* */
public class MaxLengthWatcher implements TextWatcher {
private int maxLen = 0;
private EditText editText = null;
public MaxLengthWatcher(int maxLen, EditText editText) {
this.maxLen = maxLen;
this.editText = editText;
}
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
Editable editable = editText.getText();
int len = editable.length();
if(len > maxLen)
{
int selEndIndex = Selection.getSelectionEnd(editable);
String str = editable.toString();
//截取新字符串
String newStr = str.substring(0,maxLen);
editText.setText(newStr);
editable = editText.getText();
//新字符串的长度
int newLen = editable.length();
//旧光标位置超过字符串长度
if(selEndIndex > newLen)
{
selEndIndex = editable.length();
}
//设置新光标所在的位置
Selection.setSelection(editable, selEndIndex);
}
}
}
对应的 activity 部分的调用为:
[java] view plainprint?
01.package cie.textEdit;
02.
03.import android.app.Activity;
04.import android.os.Bundle;
05.import android.text.InputFilter;
06.import android.widget.EditText;
07.
08.public class TextEditActivity extends Activity {
09. /** Called when the activity is first created. */
10. @Override
11. public void onCreate(Bundle savedInstanceState) {
12. super.onCreate(savedInstanceState);
13. setContentView(R.layout.main);
14.
15. EditText editText = (EditText) findViewById(R.id.entry);
16. editText.addTextChangedListener(new MaxLengthWatcher(10, editText));
17.
18. }
19.}
package cie.textEdit;
import android.app.Activity;
import android.os.Bundle;
import android.text.InputFilter;
import android.widget.EditText;
public class TextEditActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText editText = (EditText) findViewById(R.id.entry);
editText.addTextChangedListener(new MaxLengthWatcher(10, editText));
}
}
限制输入字符数为10个
main.xml 文件
[html] view plainprint?
01.<?xml version="1.0" encoding="utf-8"?>
02.<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
03. android:layout_width="fill_parent"
04. android:layout_height="fill_parent">
05. <TextView
06. android:id="@+id/label"
07. android:layout_width="fill_parent"
08. android:layout_height="wrap_content"
09. android:text="Type here:"/>
10. <EditText
11. android:id="@+id/entry"
12. android:singleLine="true"
13. android:layout_width="fill_parent"
14. android:layout_height="wrap_content"
15. android:background="@android:drawable/editbox_background"
16. android:layout_below="@id/label"/>
17. <Button
18. android:id="@+id/ok"
19. android:layout_width="wrap_content"
20. android:layout_height="wrap_content"
21. android:layout_below="@id/entry"
22. android:layout_alignParentRight="true"
23. android:layout_marginLeft="10dip"
24. android:text="OK" />
25. <Button
26. android:layout_width="wrap_content"
27. android:layout_height="wrap_content"
28. android:layout_toLeftOf="@id/ok"
29. android:layout_alignTop="@id/ok"
30. android:text="Cancel" />
31.</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type here:"/>
<EditText
android:id="@+id/entry"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/label"/>
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="OK" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="Cancel" />
</RelativeLayout>