androidedittext監聽
⑴ Android studio怎麼給按鈕設置監聽,並讓editText顯示文字
假設你的按鈕拖拽在activity_main.xml文件裡面,你的監聽就是在Myactivity.java設置(簡單說就是你在哪個xml文件里放置了一個按鈕,就在哪個對應xml的java文件寫),而不需要新建一個class
接下來的是設置監聽
設置監聽第一步:
聲明一個Button按鍵(btn1是自己命名)
找到EditText的位置(給剛剛命名的EditText賦值)
也是在setContentView(R.layout.****);的下面輸入下面的代碼
然後在倒數第一個 } 前面輸入
String str1 = et3.getText().toString();//獲取文本框的內容並賦值給str1
String str2 = et4.getText().toString();//獲取文本框的內容並賦值給str2
String str3 = et5.getText().toString();//獲取文本框的內容並賦值給str3
str1、str2、str3是自己命名的字元串,到後面你想要用到文本框的內容就輸入str這些自己命名的String
希望能幫到你
⑵ android EditText控制項有沒有離開監聽事件
獲得焦點:有游標近來onTextChanged:正在輸入時的時間失去焦點:就是游標離開了。
⑶ android中edittext怎麼監聽字體長度
這個監聽就是addTextChangedListener(EditText s).
{
privateEditTextadb_password;
publicbooleanchange=false;
privateLinearLayoutadb_lin2;
privateButtonbutton1;
privateButtonbutton2;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.kvadb);
adb_password=(EditText)findViewById(R.id.adb_password);
adb_lin2=(LinearLayout)findViewById(R.id.adb_lin2);
button1=(Button)findViewById(R.id.button1);
button2=(Button)findViewById(R.id.button2);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
adb_password.addTextChangedListener(mEditText);
}
TextWatchermEditText=newTextWatcher(){
privateCharSequencetemp;
@Override
publicvoidonTextChanged(CharSequences,intstart,intbefore,intcount){
temp=s;
}
@Override
publicvoidbeforeTextChanged(CharSequences,intstart,intcount,
intafter){
adb_password.setVisibility(View.VISIBLE);
adb_lin2.setVisibility(View.GONE);
}
@Override
publicvoidafterTextChanged(Editables){
if(adb_password.getText().length()==6){
if(adb_password.getText().toString().equals("111111")){
adb_password.setVisibility(View.GONE);
adb_password.setFocusableInTouchMode(false);
adb_password.setFocusable(false);
adb_lin2.setVisibility(View.VISIBLE);
adb_lin2.setFocusableInTouchMode(true);
button1.requestFocus();
}
}
}
};
@Override
publicvoidonClick(Viewv){
switch(v.getId()){
caseR.id.button1:
Toast.makeText(KvAdb.this,"llll",0).show();
break;
caseR.id.button2:
finish();
break;
}
}
}
⑷ android如何實時監聽edittext的內容,對sqlite里的內容進行查詢
//藉助TextWatcher類
privateTextWatcherwatcher=newTextWatcher(){
@Override
publicvoidafterTextChanged(Editables){
//TODOAuto-generatedmethodstub
}
@Override
publicvoidbeforeTextChanged(CharSequences,intstart,intcount,
intafter){
//TODOAuto-generatedmethodstub
}
@Override
publicvoidonTextChanged(CharSequences,intstart,intbefore,
intcount){
//Log.d("TAG","[TextWatcher][onTextChanged]"+s);
//dosomething
}
};
//在EditText上注冊該TextWatcher實例
EditTextet=(EditText)findViewById(R.id.edit);
et.addTextChangedListener(watcher);
⑸ android edittext監聽 搜索
android edittext監聽 搜索
UDP是User Datagram
Protocol的簡稱,中文名是用戶數據包協議,是OSI參考模型中一種無連接的傳輸層協議,提供面向事務的簡單不可靠信息傳送服務。它是IETF
RFC
768是UDP的正式規范。在網路中它與TCP協議一樣用於處理數據包。在OSI模型中,在第四層-傳輸層,處於IP協議的上一層。UDP有不提供數據報
分組、組裝和不能對數據包的排序的缺點,也就是說,當報文發送之後,是無法得知其是否安全完整到達的。UDP用來支持那些需要在計算機之間傳輸數據的網路
應用。包括網路視頻會議系統在內的眾多的客戶/伺服器模式的網路應用都需要使用UDP協議。UDP協議從問世至今已經被使用了很多年,雖然其最初的光彩已
經被一些類似協議所掩蓋,但是即使是在今天,UDP仍然不失為一項非常實用和可行的網路傳輸層協議。
⑹ Android開發 我想設置edittext 輸入完成後在調用監聽方法 這個怎麼實現
et.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {//在輸入數據時監聽
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,//輸入數據之前的監聽
int after) {
}
@Override
public void afterTextChanged(Editable s) {//輸入數據之後監聽
}
}
}
你還以在afterTextChanged(Editable s){ }中 同handler去延遲幾秒 就可以了
⑺ android怎麼監聽輸入字
使用EditText的addTextChangedListener(TextWatcher watcher)方法對EditText實現監聽,TextWatcher是一個介面類,所以必須實現TextWatcher里的抽象方法:
當EditText裡面的內容有變化的時候,觸發TextChangedListener事件,就會調用TextWatcher裡面的抽象方法。
⑻ android如何利用button監聽edittext輸入的內容並單擊之後輸出到一個textview中
JAVA---
public void onCreate(Bundle b){
super.onCreate(b);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.button);
final EditText edit = (EditText)findViewById(R.id.edit);
final TextView text = (TextView)findViewById(R.id.text);
button.setOnClickListener(new OnClickListener(){
@Override //監聽點擊事件
public void onClick(View v) {
text.setText(edit.getText().toString());
}
});
}
XML--
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<EditText
android:id="@+id/edit"
android:inputType="text"
android:layout_width="200dip"
android:layout_height="50dip"
android:layout_alignParentTop="true">
</EditText>
<Button android:id="@+id/button"
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_below="@id/edit"/>
<TextView android:id="@+id/text"
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_below="@id/button"/>
</RelativeLayout>
代碼寫的很簡單
主要就是 text.setText(edit.getText().toString());
text是textview setText 設置其內容
edit是edittext edit.getText().toString() 獲得其內容
⑼ EditText監聽方法,實時的判斷輸入多少字元
在EditText提供了一個方法addTextChangedListener實現對輸入文本的監控。下邊是我自己寫的一個Demo。
代碼實現:
布局文件main.xml
[html] view plain
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:text="Please input the text:"
/>
<EditText android:id="@+id/ET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>