Kerv
Kerv

Reputation: 179

How to start typing at the second line in edittext?

Is there a possibility that my edittext will start typing at the second line? Assuming that the first line was an 'enter'. Is that possible? If that so, how?

This was my code that i'm talking about. Can you find a solution why it keeps on not reading the 1st line. My solution is to make the first line as 'enter' as default. Or you can find another one?

public class TestTCP
{
    private static final int PORT = 1475;

    private static ServerSocket serverSocket;
    private static Socket clientSocket;
    private static InputStreamReader inputStreamReader;
    private static BufferedReader bufferedReader;
    private static String message;
    private static String multiple;

    public static void main(String[] args)
    {
        try
        {
            serverSocket = new ServerSocket(PORT, 0, InetAddress.getLocalHost());

            System.out.println("IP:  " + serverSocket.getInetAddress() + "  Port:  " +  serverSocket.getLocalPort());

        } catch (IOException e)
        {
            System.out.println("Could not listen on port: 1447");
        }

        System.out.println("Server started. Listening to the port 1447");

        while (true)
        {
            try
            {{
                clientSocket = serverSocket.accept(); // accept the client connection
                inputStreamReader = new InputStreamReader(clientSocket.getInputStream());
                bufferedReader = new BufferedReader(inputStreamReader); // get the client message
                message = bufferedReader.readLine();

                while ((message = bufferedReader.readLine()) != null) {
                    System.out.println("Message from Table 1: " + message);}
                    inputStreamReader.close();
                    clientSocket.close();}

            } catch (IOException ex)
            {
                ex.printStackTrace();
                System.out.println("Problem in message reading");
            }
            finally {
                try {
                    if (bufferedReader != null)bufferedReader.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
        }
    }
}}

Upvotes: 2

Views: 239

Answers (2)

Caleb Bramwell
Caleb Bramwell

Reputation: 1342

Try this

EditText mEditText;
@Override onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mEditText = (EditText) findViewById(R.id.edittext);
    mEditText.append("\n");
}

Upvotes: 3

Max
Max

Reputation: 13358

Set an ontouch listener for the edittext:

editText1.setOnTouchListener(new OnTouchListener() {
    @Override
    public void onTouch(View v, MotionEvent event) {
        editText1.setText("\n");
    }
});

The editText will skip a line when touched, this code is just an example. You will need to improve it a bit for your needs.

Make sure you refer to this method from the onCreate method.

Upvotes: 1

Related Questions