我的应用程序有两个EditText元素.两者都像这样实现OnClickListener:
editText1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Open search dialog
doSomeStuff();
}
});
Run Code Online (Sandbox Code Playgroud)
doSomeStuff()表示:单击文本字段可打开搜索对话框onSearchRequested().搜索结果将写回文本字段.
这工作正常但如果我单击其他文本字段,我总是必须在搜索对话框出现之前单击两次.它来自何处以及如何更改它以便在单击一次时出现搜索对话框?
我已经使EditTextPreference'textPasscode'依赖于CheckBoxPreference'checkBoxPasscode'.我想在用户选中复选框后立即打开'textPasscode'.它甚至可能吗?如果是,我可以在onSharedPreferenceChanged()函数中使用什么?
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if(key.contentEquals("checkBoxPasscode")){
// ----some method to open edit text "textPasscode" ??
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个EditText过滤ListView下面的项目,通常可能包含超过1000个项目.该TextWatcher方法是:
txt_itemSearch.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
fillItemList();
}
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
});
Run Code Online (Sandbox Code Playgroud)
这里的问题是,对于用户键入的每个字母,列表都会刷新,这是重复列表更新,导致UI变慢.
如何TextWatcher等待1-2秒,如果2秒后没有更多输入,则过滤列表.有什么建议吗?
我有这种奇怪的行为,我无法解释.我的布局很简单:一个EditText:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp" >
<EditText
android:id="@+id/etPass"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
当我尝试longPress它(粘贴一些文本)我得到一个临时强制关闭和这个错误:
05-08 16:56:16.838: E/AndroidRuntime(12164): FATAL EXCEPTION: main
05-08 16:56:16.838: E/AndroidRuntime(12164): android.view.InflateException: Binary XML file line #17: Error inflating class <unknown>
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-08 16:56:16.838: E/AndroidRuntime(12164): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-08 16:56:16.838: E/AndroidRuntime(12164): at android.widget.Editor$ActionPopupWindow.initContentView(Editor.java:2995)
05-08 16:56:16.838: …Run Code Online (Sandbox Code Playgroud) 我有这个edittext:
<EditText android:inputType="textMultiLine|textCapSentences"
android:layout_width="fill_parent"
android:layout_height="240dp"
android:scrollHorizontally="false"
android:imeOptions="actionNone"
android:minLines="9"
android:scrollbars="vertical"
android:singleLine="false"
android:gravity="top"
android:layout_gravity="center_vertical|left"
android:nextFocusForward="@+id/costo_dettagli"
android:layout_weight="1"
android:id="@+id/dettagli"
android:textSize="20sp" />
Run Code Online (Sandbox Code Playgroud)
这部分清单:
android:windowSoftInputMode="stateHidden|adjustPan"
Run Code Online (Sandbox Code Playgroud)
问题?当键盘出现时,它会在闪烁的光标下方(换句话说在第一行),而不是在整个edittext下面!需要将键盘放在小部件下方.
我的所有布局都在一个scrollview中,我已经尝试了所有的android:windowSoftInputMode
edittext问题http://imageshack.com/a/img199/9295/jmgb.png
我勒个去??我需要帮助.
我知道这个/类似的问题之前已被问到,但给出的解决方案对我不起作用,所以我再问一次.我尝试了该答案中给出的解决方案,但仍然在某些设备上调用我的OnKeyListener,尤其是那些具有库存操作系统的设备.当editText中没有字符时,我需要检测按下软键盘的del键.这是我的代码;
EditText et = (EditText) findViewById(R.id.et);
et.setOnKeyListener(new EditText.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
Log.d("OnKeyListener", keyCode + " character(code) to send");
return false;
}
});
Run Code Online (Sandbox Code Playgroud) 如果用户只在EditText中输入空格但我不知道如何,我想显示错误?
这是我的简单工作
if (tName.getText().toString().matches(" ")) {
Toast.makeText(MainActivity.this, "Must Add Your Name Here", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud) 我希望实现像这样的东西.带有两个编辑文本的浮动标签.我也使用TextInputLayout过其他一些图书馆,但都只接受单身儿童EditText.任何帮助表示赞赏.
两个编辑文本都必须是可聚焦的,并且提示从第二个上升.
android android-edittext material-design android-textinputlayout
我正在尝试从ListView中的EditText获取数据.我看到了很多类似的问题,并得到了解决方案.但它在我的实施中抛出了一个NPE.
所以请指导我解决这个问题.
适配器
public class Coscho_adapter extends BaseAdapter {
Context con;
ArrayList<HashMap<String, String>> list;
LayoutInflater mInflater;
EditText marks;
TextView studname, acname;
public Coscho_adapter(Context co, ArrayList<HashMap<String, String>> list1) {
list = list1;
con = co;
mInflater = (LayoutInflater) con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int arg0) {
return null;
}
@Override
public long getItemId(int arg0) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder; …Run Code Online (Sandbox Code Playgroud) 我试图更改EditText光标指针颜色(从原色蓝色到白色),但没有解决方案适用于我的项目.我试图开发演示项目,其中相同的代码工作正常.这段代码适用于> = android 5.0
我不知道,我的值会覆盖哪个属性.我有两个选项可以解决这个问题: -
1.找到控制该颜色值的属性.
2.页面加载时(在onViewCreated中)通过java代码更改颜色值.
请建议如何解决此问题.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="my_text_layout_style">
<item name="android:textColor">#FFF</item>
<item name="android:textColorHint">#FFF</item>
<item name="colorAccent">#FFF</item>
<item name="colorControlNormal">#FFF</item>
<item name="colorControlActivated">#FFF</item>
<item name="colorControlHighlight">#FFF</item>
</style>
<style name="my_edit_text_style">
<item name="colorAccent">#FFF</item>
<item name="android:editTextStyle">@style/MyEditTextStyle</item>
</style>
<style name="MyEditTextStyle" parent="Widget.AppCompat.EditText" />
</resources>
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/base_disable_btn_bg_color"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:hint="just a hint"
app:hintTextAppearance="@style/my_text_layout_style"
android:theme="@style/my_text_layout_style"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:theme="@style/my_edit_text_style"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
AppLinearLayout appLinearLayout = (AppLinearLayout) view.findViewById(R.id.some_id);
EditText editText = new EditText(new ContextThemeWrapper(getContext(), …Run Code Online (Sandbox Code Playgroud) android ×10
android-edittext ×10
baseadapter ×1
keyboard ×1
keylistener ×1
listview ×1
multiline ×1
preferences ×1
search ×1
textwatcher ×1
validation ×1