7

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.

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.

I have no idea why!

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>

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); 

    }

}

Thanks for reading

Atul O Holic
  • 6,692
  • 4
  • 39
  • 74
Smittey
  • 2,475
  • 10
  • 28
  • 35
  • Main reason of this issue is only android:hardwareAccelerated="false" either added to that particular activity or in application tag of AndroidManifest.xml. Better remove from everywhere if not mandatory to have else keep it android:hardwareAccelerated="true" – Ready Android Apr 05 '21 at 11:51

3 Answers3

30

It works for me may be helpful to others as well, open your manifest file and set hardwareAccelerated="true".

 <application
    android:allowBackup="true"
    .....
    android:hardwareAccelerated="true">

For more about HardwareAccelerated https://developer.android.com/guide/topics/graphics/hardware-accel.html

Naeem Ibrahim
  • 3,375
  • 1
  • 21
  • 21
  • This helped me. The code I was working on wasn't mine. And very strangely for the specific activity in question this attribute was set to false. – CanonicalBear Jul 08 '20 at 12:52
4

In fact your text is being typped, but that's a little bug that makes your text color be the same as your background, so you don't see it. This can be easily fixed by doing 2 things:

1) Simply change the textColor of your EditText, either defining it in the layout:

android:textColor="..."

or dynamically:

EditText et = (EditText) findViewById(R.id.your_edittext);
et.setTextColor(Color.RED);

2) Change the extended theme in your manifest:

<application android:theme="@style/Theme.Light.NoTitleBar.Workaround" ... >

3) Create the new theme at res/values/themes.xml which uses fixed styles:

<style name="Theme.Light.NoTitleBar.Workaround" parent="@android:style/Theme.Light.NoTitleBar">
  <item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewLight</item>
  <item name="android:dropDownItemStyle">@style/Widget.DropDownItemLight</item>
</style>

4) Now these styles, located at res/values/styles.xml should fix the color:

<style name="AutoCompleteTextViewLight" parent="@android:style/Widget.AutoCompleteTextView">
  <item name="android:textColor">@android:color/primary_text_light</item>
</style>
<style name="Widget.DropDownItemLight" parent="@android:style/Widget.DropDownItem">
  <item name="android:textColor">@android:color/primary_text_light</item>
</style>

I know it's a mess, but try it and if it works, try finding a combination of those attributes that fit to your layout.

nKn
  • 13,691
  • 9
  • 45
  • 62
  • 1
    Thanks for the suggestion! I tried both of those but it didn't work. You see, the problem isn't that I can't see the text at all, it's that it is only displayed once the keyboard is closed down. I need it to be displayed as you type in real-time – Smittey Feb 11 '14 at 19:42
  • Sorry, there was one step to go! I updated my post, have a look at it, hope this time it helps. – nKn Feb 11 '14 at 19:43
  • Good suggestions! I found a similar problem here [link](https://groups.google.com/forum/#!topic/android-developers/3kfWpxvaP4U) and that lead me down the route of your suggestions. However, after trying, the colour still remains white (I gather is the issue), until the keyboard is closed. – Smittey Feb 11 '14 at 20:22
  • Hm, strange - every time I've use this approach or suggested it, it worked like a charm. Try however changing the textcolor of the `EditBox` between different colors, and see if it changes. For instance, set the `android:textColor="#FF0000"` and see what happens. – nKn Feb 11 '14 at 20:28
  • Hmm... Perhaps I missed something out (I'm rather new to android development). I did the following: I added your code to styles.xml in the tag and android:theme="@style/Theme.Light.NoTitleBar.Workaround"> to the manifest Is this correct? – Smittey Feb 11 '14 at 21:04
  • Something has also gone slightly wrong.. I'm getting the following error: "error: Error: No resource found that matches the given name (at 'android:autoCompleteTextViewStyle' with value '@style/AutoCompleteTextViewLight')." – Smittey Feb 11 '14 at 21:06
  • Also, it's terrible quality, but here is a recording of the problem just in case it isn't clear (I don't think I did a great job of explaining it) [link](http://postimg.org/image/pngsx6h21/) – Smittey Feb 11 '14 at 21:18
  • I'm sorry for such a concise description, posting things from the office is not a good idea. I've updated my answer with the full steps (I had them within a document in my comp), hope **this** time will work. – nKn Feb 11 '14 at 22:42
  • Thanks @NKN, I found what the problem was (posted as an answer). I found what you said useful though as I'd never done that before - so thank you – Smittey Feb 12 '14 at 13:16
1

Ok, so I worked out what the issue was!

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);

    }
 }; 

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.

Thank you to @NKN who helped me.

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

Smittey
  • 2,475
  • 10
  • 28
  • 35