我有一个EditText-Field并为它设置一个OnFocusChangeListener.当它失去焦点时,会调用一个方法,该方法使用数据库中的一个方法检查EditText的值.如果方法的返回值为true,则显示toast,焦点应再次返回EditText.焦点应始终返回EditText并且键盘应该显示,直到方法的返回值为false.
编辑:我想,我还没有完全清楚我的真正问题:屏幕上没有其他项目应该能够编辑,直到EditText的值被编辑为一个值,这使得方法"checkLiganame(liganame) "回归虚假.只有EditText-Field应该是可编辑的.
这是我的代码(这对我不起作用):
final EditText Liganame = (EditText) findViewById(R.id.liganame);
Liganame.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
String liganame = Liganame.getText().toString();
if (checkLiganame(liganame)) {
Toast toast = Toast.makeText(CreateTableActivity.this,
"Dieser Liganame ist bereits vergeben",
Toast.LENGTH_SHORT);
toast.show();
Liganame.requestFocus();
}
}
Run Code Online (Sandbox Code Playgroud)
和方法:
public boolean checkLiganame(String liganame) {
boolean found = false;
DatabaseHelper databaseHelper = new DatabaseHelper(this);
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor cursor = db.query("liga", new String[] { "liganame" },
"liganame = '" + liganame + "'", …Run Code Online (Sandbox Code Playgroud) 我有一个布局,其中包含一些像这样的视图:
<LinearLayout>
<TextView...>
<TextView...>
<ImageView ...>
<EditText...>
<Button...>
</linearLayout>
Run Code Online (Sandbox Code Playgroud)
如何以EditText编程方式设置焦点(显示键盘)?
我已经尝试了这个,只有当我Activity正常启动时它才有效,但是当我在a中启动它时TabHost,它不起作用.
txtSearch.setFocusableInTouchMode(true);
txtSearch.setFocusable(true);
txtSearch.requestFocus();
Run Code Online (Sandbox Code Playgroud) 当EditText失去焦点时我需要抓住,我已经搜索了其他问题,但我没有找到答案.
我用OnFocusChangeListener这样的
OnFocusChangeListener foco = new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
}
};
Run Code Online (Sandbox Code Playgroud)
但是,它对我不起作用.
我只是想在某个EditText具有焦点时立即切换到数字键盘模式.
我需要一个EditText看起来像这样的onError:
调用onError看起来像这样:

注意:该应用程序在SDK 19(4.4.2)上运行
min SDK是1
有没有类似于setError的方法自动执行此操作,还是我必须为其编写代码?
谢谢
在我的应用程序中,我必须经常在两个布局之间切换.错误发生在下面发布的布局中.
第一次调用我的布局时,没有发生任何错误,一切都很好.当我再调用一个不同的布局(一个空白的布局),然后再次调用我的布局时,它会给我以下错误:
> FATAL EXCEPTION: main
> java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Run Code Online (Sandbox Code Playgroud)
我的布局代码如下所示:
tv = new TextView(getApplicationContext()); // are initialized somewhere else
et = new EditText(getApplicationContext()); // in the code
private void ConsoleWindow(){
runOnUiThread(new Runnable(){
@Override
public void run(){
// MY LAYOUT:
setContentView(R.layout.activity_console);
// LINEAR LAYOUT
LinearLayout layout=new LinearLayout(getApplicationContext());
layout.setOrientation(LinearLayout.VERTICAL);
setContentView(layout);
// TEXTVIEW
layout.addView(tv); // <========== ERROR IN THIS LINE DURING 2ND RUN
// EDITTEXT
et.setHint("Enter Command");
layout.addView(et); …Run Code Online (Sandbox Code Playgroud) 我正在使用TextInputLayout设计库中的新功能.我可以让它显示并更改浮动标签的颜色.不幸的是,实际EditText提示现在总是白色的.
我试过用XML,样式和编程方式更改hintColor,并尝试使用android.support.v7.widget.AppCompatEditText
但EditText提示总是显示白色.
这是我TextInputLayout和我的XMLEditText
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android.support.design:hintTextAppearance="@style/GreenTextInputLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/city"
android:textColorHint="@color/black"
android:hint="@string/city" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的样式TextInputLayout(我尝试将hintTextColor属性设为黑色,但没有为我做任何事情):
<style name="GreenTextInputLayout" parent="@style/TextAppearance.AppCompat">
<item name="android:textColor">@color/homestory_green</item>
</style>
Run Code Online (Sandbox Code Playgroud) android android-edittext android-textattributes android-support-library android-design-library
在我的Android应用程序中,我有不同EditText的用户可以输入信息的位置.但是我需要强制用户用大写字母书写.你知道这样做的功能吗?
我需要在Android UI中绘制一个圆角矩形.具有相同的圆角矩形TextView,并EditText也将是有益的.
android ×10
android-edittext ×10
focus ×2
textview ×2
java ×1
keyboard ×1
lostfocus ×1
parent-child ×1
softkeys ×1
uppercase ×1