㈠ 安卓系統 智能手機 一條簡訊字數的最大限制是多少
您好,一條普通簡訊的長度為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>