1

i wanted to create a terminal/console, where the user can enter commands. I know java, but i'm new to xml, so i wanted to know how i can spawn text under text and if it gets to long it should be scrollable, here's a picture:

enter image description here

and here's my xml cpde for it:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#d1d1d1">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="1">

        <EditText
            android:layout_width="175dp"
            android:layout_height="wrap_content"
            android:id="@+id/consoleText"
            android:layout_gravity="bottom"
            android:hint="Command"
            android:layout_weight="0.99" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Send"
            android:id="@+id/sendButton"
            android:layout_gravity="bottom" />
    </LinearLayout>

</LinearLayout>

and here's my code for getting the text:

public class FragmentConsole extends Fragment{
    EditText text;
    Button button;
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.console,
                container, false);
        button = (Button) view.findViewById(R.id.sendButton);
        text = (EditText)view.findViewById(R.id.consoleText);
        button.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                Log.v("EditText", text.getText().toString());
            }
        });
        return view;
    }
}

So i will use some photoshopped pictures to show what i want to do, so each time i enter a command in this case i will use the example "command one","command two" & "command three", so and if i click the send button after each of them they should apper like this:

enter image description here

so and if the text reaches this black bar:

enter image description here

the above added text should get pushed in a scrollview and every new text will also get part of the scrollview, so that you can scroll through your commands later on. I know this is a long post and i hope it is clear what i want to do and someone will know how i could do this. So thanks in advance :)

N.W.A
  • 65
  • 9
  • Tip: Why do you use **2** nested LinearLayouts instead of **1** single RelativeLayout? – Phantômaxx Jan 23 '16 at 17:40
  • I don't i'm new to xml and android app making and for me it worked well so i thought i could do it like so :S – N.W.A Jan 23 '16 at 17:43
  • Well, nested layouts are, in general, something to avoid, if you care for performances. Always keep in mind: the flatter, the better. – Phantômaxx Jan 23 '16 at 17:45
  • okay, will do in the future ;) you seem to have someknowledge on this do you maybe know how i could do this? – N.W.A Jan 23 '16 at 17:50
  • Google keywords: `android execute command line` – Phantômaxx Jan 23 '16 at 17:52
  • i googled before and i didn't found anything relating to this topic... – N.W.A Jan 23 '16 at 17:55
  • But I found MANY relevant results, by using those keywords. – Phantômaxx Jan 23 '16 at 17:55
  • yeah then show me how to because i didn't found anything on how to check if the text i spawn underneath is passing a point and then putting it in a scrollview -.- – N.W.A Jan 23 '16 at 17:57
  • Simply include your TextView in a ScrollView. Done. – Phantômaxx Jan 23 '16 at 17:58
  • ohh wow, yeah that's obvious but how would i check in java code if my text passed a specific y coordinate and then playce all the text i spawned and further text into a scrollview – N.W.A Jan 23 '16 at 18:01
  • how should i do it then!? – N.W.A Jan 23 '16 at 18:03
  • I can't unerstand your difficulties... **1** - Write the text into the EditText. **2** - Click the Button. **3** - Append the text into the TextView. **4** - Execute the command. Finished. – Phantômaxx Jan 23 '16 at 18:10
  • this is easy but how can i check if the textview size passed a y-coordinate in this case where my edittextbox is and the put it in a scrollview – N.W.A Jan 23 '16 at 18:26
  • You are misunderstanding the usage of the ScrollView. You don't have to worry about that. The TextView will grow indefinetely inside the ScrollView. Without you having to calculate anything – Phantômaxx Jan 23 '16 at 18:40
  • You need to dig in [this](http://stackoverflow.com/questions/1748977/making-textview-scrollable-in-android?lq=1) direction. – Onik Jan 23 '16 at 21:42

1 Answers1

2

For this task you should consider using ListView and add every command as new row in this view. It'll also take care for scrolling and you'r text wont colide with your EditText.

  • This is another possibility. Even better, because by doing so the commands can be re-executed without having to type them again. – Phantômaxx Jan 23 '16 at 18:44