我想要做的是更改虚拟键盘中显示的默认"完成"标签.这是我没有运气的尝试:
mSearchInput.setImeOptions(EditorInfo.IME_ACTION_DONE);
mSearchInput.setImeActionLabel(getString(R.string.search_action_label), EditorInfo.IME_ACTION_DONE);
Run Code Online (Sandbox Code Playgroud)
我很能干,但是,处理该按钮的点击,这一点:
mSearchInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
performSearch();
return true;
}
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
我对如何在此刻更改该按钮上的标签毫无头绪.
如何使用手机输入和隐藏字符串的功能获取Edittext.我知道
android:inputType="textPassword"
Run Code Online (Sandbox Code Playgroud)
隐藏字符串,而
android:inputType="phone"
Run Code Online (Sandbox Code Playgroud)
打开拨号盘界面.
如何将两者结合起来?
我正在尝试使用Typeface在我的项目中使用字体.我将其复制"font.ttf"到"assets"文件夹中名为"fonts"的文件夹中.但是eclipse不允许编译它.它在fonts文件夹中显示错误.我该怎么办?
我得到的错误是:
invalid resource directory name fonts /NoRats/assets line 1 Android AAPT Problem
Run Code Online (Sandbox Code Playgroud) 我有验证editText.如果该editText字段为空,则应验证失败并停止用户移动到另一个Activity,因为需要值.怎么做?我知道这是一个基本问题,但我无法弄清楚如何做到这一点.
我的代码:
btninsert = (Button)findViewById(R.id.btn_insert);
btninsert.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
insertValues();
EditText userName = (EditText) findViewById(R.id.editText1);
if( userName.getText().toString().length() == 0 )
userName.setError( "First name is required!" );
Intent i = new Intent(getApplicationContext(), Login.class);
startActivity(i);
}
});
Run Code Online (Sandbox Code Playgroud)
Button 单击此按钮时,用户将重定向到下一个屏幕,但是如果验证失败,我需要保持当前状态Activity,并且只有在验证成功时(即已输入值),他们才会转到下一个屏幕Activity.
我创建了一个ListView(myList),每行有一个EditText-Field(R.id.mannschaften).在ListView下,我创建了一个Button,并在OnCreate() - Method中为它设置了一个OnClickListener.现在,当单击Button时,我想迭代ListView并获取每行中EditText-Field的值并将它们保存在String-List中.但是我该怎么做?
这是我的代码:
private void ButtonClick() {
/** get all values of the EditText-Fields */
View v;
ArrayList<String> mannschaftsnamen = new ArrayList<String>();
EditText et;
for (int i = 0; i < myList.getCount(); i++) {
v = myList.getChildAt(i);
et = (EditText) v.findViewById(R.id.mannschaften);
mannschaftsnamen.add(et.getText().toString());
}
.....
}
Run Code Online (Sandbox Code Playgroud)
我已经知道,getChildAt仅适用于可见行,但我不知道如何以不同方式执行.
我TextInputLayout在我的Android应用程序中使用,以便为我的输入字段实现整洁的浮动标签效果.我知道我也应该使用它TextInputEditText来允许在横向模式下显示提示并且输入填满整个屏幕.
但是,在我的一些输入字段中,我已经使用了自动完成AutoCompleteTextView(IMO的名称确实不一致 - "TextView"而不是"EditText" - 但这是另一个故事)并且显然是直接继承的EditText.因此它没有带来的功能TextInputEditText.
所以我想知道是否有办法实现相同的景观功能(没有自己的TextInputAutoCompleteTextView实现,也就是这样),并且还避免产生的lint警告.我在这里错过了什么吗?我想我得到的是他们没有EditText为这个特定事物制作所有直接和间接子类的自定义版本,所以我希望自己制作?
android autocomplete autocompletetextview android-edittext android-textinputlayout
我的活动的布局如下所示.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<FrameLayout android:id="@+id/title_bar"
android:layout_width="fill_parent"
android:layout_height="25dip"
android:background="@drawable/bg_title" />
<LinearLayout android:id="@+id/main"
android:width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dip" >
<EditText android:id="@+id/query"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter some search terms"
android:singleLine="true"
android:layout_weight="1" />
<Button android:id="@+id/btn_hide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_hide"
android:layout_marginLeft="6dip" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
因此,搜索框固定在屏幕的底部.
但是,当用户单击EditText时,软键盘会显示并将布局推出屏幕,但搜索框除外.
我刚刚开始使用Android,所以我在这里做错了什么?
我遇到了EditText控件的问题.此问题仅发生在此特定活动上,而没有其他活动与EditTexts.我删除了此EditText的所有setText调用,问题仍然存在.
我在移动设备上运行Android 2.3.4.这是一款Nexus S和Android的运行股票.在模拟器(运行Android 2.2)中,不会发生此问题.
当我旋转手机时,Android会自动替换旋转前EditText中的文本.我没有使用savedInstanceState来做任何事情.Android正在做这件事.
我的问题:
假设单词"test"在EditText中.当我旋转手机时,Android会在重新创建活动时将"testtest"放入EditText.这只是发生在我使用虚拟键盘输入到EditText上,我不点击虚拟键盘上的"完成"按钮,我按回到删除虚拟键盘,然后转动的装置.如果我使用"完成"按钮而不是后退按钮,则不会出现问题.
有任何想法吗?正如我所说,我不是在设置文本.调用setText的所有行都已注释掉.
更新1:除了onCreate()方法之外,我已经注释掉了这个Activity中的所有内容.问题仍然存在.
更新2:我创建了一个新的Activity.这个全新的Activity只有一个onCreate()方法.onCreate()方法中唯一的事情是调用setContentView(使用相同的布局文件)并调用super的onCreate().问题仍然存在.我很难过.我唯一可以猜到的是布局文件有些不可思议.我不知道那会是什么.
更新3:除了EditText之外,我已经从布局中删除了所有内容.问题仍然存在.
我的布局上有一个EditText.在用户输入一些文本并点击"完成"键后,我想从中删除闪烁的光标.我已经搜索了StackOverflow并找到了3个对我不起作用的答案.闪烁的光标仍然存在.
private class MyOnKeyListener implements OnKeyListener {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& keyCode == KeyEvent.KEYCODE_ENTER) {
// FAIL 0
MyActivity.this.findViewById(R.id.someOtherView).requestFocus();
// FAIL 1
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE
);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
// FAIL 2
MyActivity.this.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
);
return true;
} else {
return false;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有3个屏幕状态的片段; 添加,编辑和查看.在Add中,我创建一个实体并保存它.下次我在View模式下打开它并使用设置实体名称
EditText entityName = (EditText) view.findViewById(R.id.entityName);
entityName.setText(entity.getEntityname());
Run Code Online (Sandbox Code Playgroud)
我从"查看"模式中单击"编辑"按钮以打开"编辑"模式.我在这里更改实体名称并保存.这让我回到了视图屏幕.但我发现实体名称没有更新.我调试,发现它entity.getEntityname() 具有正确的价值.我不确定编辑文本为什么不采用新值.
有任何想法吗?
注意:我使用的是Android 2.2版
android ×10
android-edittext ×10
autocomplete ×1
java ×1
listview ×1
rotation ×1
textview ×1
validation ×1