如何在edittext的第二行开始输入?

时间:2013-08-28 19:40:55

标签: java android

我的edittext是否有可能在第二行开始输入?假设第一行是'enter'。那可能吗?如果那样,怎么样?

这是我正在谈论的代码。你能找到一个解决方案,为什么它继续不读第一行。我的解决方案是将第一行设为'enter'作为默认值。或者你可以找到另一个?

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

2 个答案:

答案 0 :(得分:3)

试试这个

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

答案 1 :(得分:1)

ontouch listener设置edittext

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

editText会在触摸时跳过一行,此代码只是一个示例。您需要根据自己的需要进行一些改进。

请务必参考onCreate method

中的此方法