2

我的编辑文本是否有可能在第二行开始输入?假设第一行是“输入”。那可能吗?如果是这样,怎么做?

这是我正在谈论的代码。你能找到一个解决方案,为什么它一直不读第一行。我的解决方案是默认将第一行设为“输入”。或者你可以再找一个?

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

2 回答 2

3

尝试这个

EditText mEditText;
@Override onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mEditText = (EditText) findViewById(R.id.edittext);
    mEditText.append("\n");
}
于 2013-08-28T20:02:34.220 回答
1

为: ontouch listener_edittext

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

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

确保您从onCreate method.

于 2013-08-28T19:53:06.547 回答