![](/img/trans.png)
[英]rich:pickList selection buttons arrow in right-to-left language direction
[英]Android Left and Right Arrow Keys Act as Back and Previous Buttons
我正在處理具有多個片段的應用程序。 在一個片段下,我有一些文本可編輯字段。 每次用戶單擊該字段時,輸入文本並單擊向左或向右箭頭鍵,然后在該字段中導航,則向左或向右箭頭鍵將作為后退或上一個按鈕,導航到下一個/上一個片段(下一個/上一個屏幕)。
我有以下一些自定義的xml字段
<com.UI.widget.UIEditText
android:id="@+id/userinfo_lastnameinput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textCursorDrawable="@null"
android:focusable="true"
android:focusableInTouchMode="true"
android:ems="10"
android:maxLength="20"
android:textColor="@color/white"
android:imeOptions="actionDone"
android:singleLine="true"
android:inputType="textPersonName" android:paddingTop="5dp"/>
相應的Java代碼是:
// Initialize the variable
mLastNameInput = (UIEditText) this.findViewById(R.id.userinfo_lastnameinput);
mLastNameInput.clearFocus();
lastNameTextChangeListener();
private void lastNameTextChangeListener() {
mLastNameInput.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
if (mInitialLoad) {
return;
}
mLastNameVar.setValue(mLastNameInput.getText().toString().trim());
mLastNameInput.setIsPending(mLastNameVar.isPending());
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// Do nothing
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// Do nothing
}
});
}
如何限制這種行為,以使箭頭鍵僅在可編輯字段內移動。
您還可以像這樣動態創建片段
// Create new fragment and
transaction Fragment newFragment = new ExampleFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
//用該片段替換fragment_container視圖中的所有內容,//並在需要時將事務添加到后台堆棧
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);
//提交交易
transaction.commit();
只需使用getSupportFragmentManager()。beginTransaction()。replace(R.id.container,fragment,“ class and / or增量”); 最好根據按鈕設計。 只需將您的XML編碼片段用作容器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.