在的EditText Android的同时,使用屏幕上的键盘打字时不显示文本 [英] EditText in Android doesn't show text when typing while using the on-screen keyboard

查看:122
本文介绍了在的EditText Android的同时,使用屏幕上的键盘打字时不显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个活动,包括3场的EditText的(除其他事项外像TextViews和几个按钮)。我也有字符串的使用ArrayAdapter列表的AutoCompleteTextView。

I have an activity consisting of 3 EditText fields (amongst other things like TextViews and a few buttons). I also have an AutoCompleteTextView with a list of String's using an ArrayAdapter.

每当我在模拟器中测试应用程序,我可以当键盘输入了,但它并没有显示文本(它仍然给predictions)和文本只有一次键盘出现在盒子的EditText关停。这发生在我测试我的手机上了。然而,它的工作原理,并显示为您在模拟器类型如果屏幕上的键盘是不是和你只是输入正常。

Whenever I test the app in an emulator, I can type when the keyboard is up but it doesn't show the text (it still gives predictions) and the text only appears in the EditText box once the keyboard is closed down. This happens when I test it on my phone, too. However, it works and shows up as you type on the emulator if the on-screen keyboard isn't up and you're just typing normally.

我不知道为什么!

下面是我的XML活动(其中的EditText的是前3块)

Here is my Activity XML (where the EditText's are the top 3 blocks)

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/l"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_x="3dp"
    android:layout_y="5dp"
    android:background="@drawable/gymbg" >


   <AutoCompleteTextView android:id="@+id/inputExercise"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:completionThreshold="1"
        android:inputType="text"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/timeSet"
        android:layout_margin="10dp"
        android:layout_marginTop="50dp"
        android:width="200dp" />  

    <EditText
        android:id="@+id/inputWeight"
        android:inputType="number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/inputExercise"
        android:layout_margin="10dp"
        android:layout_marginTop="50dp"
        android:width="200dp" >
    </EditText>

    <EditText
        android:id="@+id/inputReps"
        android:inputType="number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/inputWeight"
        android:layout_margin="10dp"
        android:layout_marginTop="50dp"
        android:width="200dp" >
    </EditText>

    <TextView
        android:id="@+id/timeMain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="@string/timeMain"
        android:textSize="32sp" 
        android:textColor="#0F293B"/>

    <TextView
        android:id="@+id/timeSet"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/timeMain"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="24dp"
        android:text="@string/timeSet" 
        android:layout_marginBottom="50dp"
        android:textColor="#0F293B"/>

    <TextView
        android:id="@+id/labExercise"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/addbutton"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/timeSet"
        android:layout_centerVertical="true"
        android:layout_margin="10dp"
        android:layout_marginLeft="15dp"
        android:text="@string/labExercise"   
        android:layout_toLeftOf="@+id/inputExercise"
        android:textColor="#ffffff"/>

    <Button
        android:id="@+id/addbutton"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_margin="10dp"
        android:text="@string/add" />


    <Button
    android:id="@+id/startStop"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:layout_above="@+id/addbutton" 
    android:layout_alignParentLeft="true"
    android:layout_margin="10dp"
    android:text="@string/startStop" />

    <TextView
        android:id="@+id/labWeight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/inputExercise"
        android:layout_margin="10dp"
        android:text="@string/labWeight" 
        android:textColor="#ffffff"/>

    <TextView
        android:id="@+id/labReps"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/inputReps"
        android:layout_margin="10dp"
        android:text="@string/labReps" 
        android:textColor="#ffffff"/>

    <TextView
        android:id="@+id/seePrevious"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/inputExercise"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="22dp"
        android:text="@string/tapToViewPrevious" 
        android:textColor="#505050"/>

</RelativeLayout>

和这里是code我在活动中使用(我已经剥离出来unneccesary code)

and here is the code I used in my activity: (I have stripped out unneccesary code)

public class MyWorkoutDiary1Activity extends Activity implements OnClickListener, TextWatcher 
{

    TextView seePrevious;
    DatabaseHandler db;

    AutoCompleteTextView myAutoComplete;

    ArrayList<String> exerciseType = new ArrayList<String>();


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        exercise = new EditText(this); 
        exercise = (EditText)findViewById(R.id.inputExercise); 

        db = new DatabaseHandler(this);
        exerciseType = db.getUniqueExercises();

        myAutoComplete = (AutoCompleteTextView)findViewById(R.id.inputExercise);

        myAutoComplete.addTextChangedListener(this);
        myAutoComplete.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, exerciseType));


        weight = new EditText(this); 
        weight = (EditText)findViewById(R.id.inputWeight); 


        reps = new EditText(this); 
        reps = (EditText)findViewById(R.id.inputReps); 

    }

}

感谢您阅读

推荐答案

好了,我的工作出了什么问题啊!

Ok, so I worked out what the issue was!

在code,我没有张贴,因为我认为这是无关紧要包含一个线程

The code which I didn't post because I thought it was 'irrelevant' contained a thread

public static Runnable updateTimerMethod = new Runnable() 
{

    public void run() 
    {
        sessionTimer.setText(TimerHandler.theTime);  

        myHandler.postDelayed(this, 0);

    }
 }; 

我意识到线程基本上是采取了所有的活动(我真的不知道该怎么解释,正确),由具有postDelayed为0。有一次,我改变了这一说... 100,那么的EditText工作。

I realised that the thread was basically taking up all of the activity (I don't really know how to explain that properly) by having the postDelayed as 0. Once I changed this to say... 100, then the EditText worked.

感谢您@NKN谁帮我。

Thank you to @NKN who helped me.

这可能是具体到我,但希望这将帮助其他人。

This may be specific to me, but hopefully this will help somebody else.

这篇关于在的EditText Android的同时,使用屏幕上的键盘打字时不显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆