12

I am currently developing an app with Samsung Galaxy Tab 2 as my device.

My Code in the XML is:

<EditText
    android:id="@+id/analysis_text"
    style="@style/icon_text"
    android:imeOptions="actionDone"
    android:inputType="textMultiLine"
    android:onClick="onBtnClicked"
/>

When this code executes, the full screen data entry mode (Extract Mode) is triggered automatically only in certain situations.

I would like my users to get a full data entry screen while editing text in this control, regardless of the screen or positioning of the control.

Another rephrase of this question: How do I force full screen data entry mode for EditText boxes in my activity no matter what the content is?

tshepang
  • 12,111
  • 21
  • 91
  • 136
skv
  • 1,793
  • 3
  • 19
  • 27
  • have you tried android:layout_width="fiil_parent" android:layout_height="fill_parent" – Usman Kurd Dec 26 '12 at 06:58
  • Thanks Usman Kurd, however my situation is slightly different, I have six such boxes, so I want them to expand to full screen only when the data entry happens. – skv Dec 26 '12 at 07:11
  • Go for AutoCompleteTectView ... – Usama Sarwar Dec 26 '12 at 07:16
  • Thanks Usama, I just tried that suggestion, it does not solve my original issue, data entry happens without the screen switching to a full screen mode – skv Dec 26 '12 at 07:26
  • A bit off the line but try to open another Activity or Fragment when EditText gets Focus. – Daksh Agrawal Jan 08 '18 at 06:08

2 Answers2

8

I solved this issue, not really solved, but found a valid work-around.

The workaround is that I designed a text editor (which looks similar to the fullscreen UI) and on click of each of those EditBoxes the new UI activity is triggerred (with the startActivityForResult() so that once they are completed control is handed back to the calling activity) and after completion of edit the text is transferred back into the main screen.

I also ensured that those boxes which transfer the control do not take focus so that they immediately transfer control to the new UI.

This way I have been able to implement a cancel button, which now actually allows the user to go back without saving the changes he accidentally makes.

I am open to new ideas, but this has worked for me.

Code in Activity:

public void onBtnClicked(View v) {
    EditText current_text_box = (EditText) v;

    Intent intent = new Intent(ObservationActivity.this,
            TexteditorActivity.class);
    intent.putExtra("start_text", current_text_box.getText().toString());
    intent.putExtra("start_position", current_text_box.getSelectionStart());
    startActivityForResult(intent, v.getId());
} 

Code in XML:

<EditText
    android:id="@+id/observation_text"
    style="@style/icon_text"
    android:focusable="false"
    android:imeOptions="flagNoExtractUi"
    android:inputType="textMultiLine"
    android:onClick="onBtnClicked" >
</EditText>

To create the full screen UI I used code, you can use any like (http://android-richtexteditor.googlecode.com/)

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
skv
  • 1,793
  • 3
  • 19
  • 27
  • 2
    This is a brilliant idea, I'm at the exact same situation and I've decided to follow your footsteps :) Cheers – Bruce Nov 11 '13 at 23:59
  • This is really a nice workaround. Please check on my question here. And let me know if you bumped into this situation. http://stackoverflow.com/questions/29786797/requestfocus-is-making-the-scrollview-to-jump-even-the-view-is-well-over-the-a – Aung Pyae Apr 22 '15 at 03:33
  • Facing 404. Help – Daksh Agrawal Jan 06 '18 at 15:31
  • @DakshAgrawal not sure if you are using Android development tools or JS based hybrids – skv Jan 07 '18 at 02:22
  • 1
    @DakshAgrawal good app, unfortunately I cant test your app because it wants my mobile number (which I am not comfortable sharing), can you explain the issue in detail, the solution here is obviously about 5 years old – skv Jan 07 '18 at 09:35
  • if you want skip having to override `onActivityResult` in the caller Activity, use a [viewModel as a singleton](https://stackoverflow.com/a/61918988/2445763) that both Activities use. This way you can rely on LiveData to store the EditText content – lasec0203 Nov 30 '20 at 22:33
0

You Can Try This

yourEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(hasFocus){
                yourEditText.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            }
        }
    });

Import LayoutParams of your Parent Layout. Your answer will also work well.

Daksh Agrawal
  • 855
  • 1
  • 11
  • 22