This time, we modify the edittext of the item to add the store name, and let the Add button change with the content of EditText. The code above is the first modification of the two controls on the XML file:
<relativelayout android:id= "@+id/et_relative" android:layout_width= "Match_parent" android: layout_height= "Wrap_content" > <edittext android:id= "@+id/addshop_et" android:layout_width= " Match_parent " android:layout_height=" wrap_content " android:textsize=" 18sp " android:hint=" shop name "/> <textview android:id= "@+id/add_shop_text" android:layout_width= "wrap_content" android:layout_ height= "Wrap_content" android:layout_alignparentright= "true" android:focusable= "true" android:o nclick= "Addshop" android:textsize= "18sp" android:layout_marginright= "5dip" android:layout_ margintop= "5dip" android:text= "@string/add_shop_btn_text" android:visibility= "Gone"/> </ Relativelayout>
Next define and initialize the corresponding control:
Private TextView add_shop_text;//Initialization control Add_textadd_shop_text = (TextView) Findviewbyid (r.id.add_shop_text);// Initialize control Addshop_edittextaddshop_et = (EditText) Findviewbyid (r.id.addshop_et);//edittext Set Listener Addshop_ Et.addtextchangedlistener (New TextChanged ());
Set the modified text content of EditText monitor addtextchangedlistener ();
Class TextChanged implements textwatcher{@Overridepublic void beforetextchanged (charsequence s, int start, int count,int After) {//TODO auto-generated method stub} @Overridepublic void OnTextChanged (charsequence s, int start, int before,int Co UNT) {//TODO auto-generated method stub} @Overridepublic void Aftertextchanged (Editable s) {}}
InaftertextchangedWrite the corresponding logic in the (Editable s) method:
if (s! = null &&! "". Equals (S.tostring ())) {add_shop_text.setvisibility (view.visible); }else {add_shop_text.setvisibility (view.invisible); }
This completes the function, which appears when the text box has content input.
Eatwhatapp Development Combat (13)