eatwhatApp開發實戰(十三)

來源:互聯網
上載者:User

標籤:

  這次內容,我們就項目中添加商店名稱的EditText進行修改,讓添加按鈕隨著edittext的內容而改變。  上代碼,首先是xml檔案上對兩個控制項的修改:
<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="店名"/><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:onClick="addShop"    android:textSize="18sp"    android:layout_marginRight="5dip"    android:layout_marginTop="5dip"    android:text="@string/add_shop_btn_text"    android:visibility="gone"/>    </RelativeLayout>
  接下來定義,並初始化對應控制項:
private TextView add_shop_text;// 初始化控制項 add_textadd_shop_text = (TextView) findViewById(R.id.add_shop_text);// 初始化控制項addshop_EditTextaddshop_et = (EditText) findViewById(R.id.addshop_et);//edittext設定監聽addshop_et.addTextChangedListener(new TextChanged());
  設定edittext的修改常值內容監聽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 count) {// TODO Auto-generated method stub}@Overridepublic void afterTextChanged(Editable s) {}}
  在afterTextChanged(Editable s)方法中寫對應邏輯:
  if(s != null && !"".equals(s.toString())){    add_shop_text.setVisibility(View.VISIBLE);  }else {    add_shop_text.setVisibility(View.INVISIBLE);  }
  這樣就完成了這個功能,在文字框有內容輸入時添加功能就會出現。

 

eatwhatApp開發實戰(十三)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.