0

如何将一个编辑文本的结果传递给另一个编辑文本?这是我的一个编辑文本的示例代码:

String a,b,c,d;  
Integer vis;  
a = txtbox1.getText().toString();  
b = txtbox2.getText().toString();
c = txtbox3.getText().toString();
d = txtbox4.getText().toString();
vis = Integer.parseInt(a)*2+Integer.parseInt(b)*3+Integer.parseInt(c)*4+Integer.parseInt(d)*5;  
tv.setText(vis.toString());

我希望将 的值tv.setText(vis.toString());转移到另一个编辑文本,我将用它作为我的异步任务(服务器-客户端通信)的输入。

谁能帮我?

异步任务:

public class ConnectToServerTask extends AsyncTask<View, Integer, Socket>
{
    private static final String IP_ADDRESS = "192.168.1.110";  // Kerv Server
    private static final int DEST_PORT = 1234; //port that is used

    private EditText kaboom;

    /**
     * Store provided views (used later in onPostExecute(...)).
     * 
     * Create socket to communicate with server (blocking call).
     */
    protected Socket doInBackground(View... params)
    {
        // Store provided views.
        if (params.length != 1)
            throw new IllegalArgumentException();

        kaboom = (EditText) params[0];


        // Create socket.
        Socket client = null;

        try
        {
            client = new Socket(IP_ADDRESS, DEST_PORT); // connect to server
        } catch (UnknownHostException e)
        {
            e.printStackTrace();
        } catch (IOException e)
        {
            e.printStackTrace();
        }

        return client;
    }

    /**
     * Write to server.
     */
    protected void onPostExecute(Socket client)
    {
        try
        {
            PrintWriter printwriter;
            String messsage;

            messsage = kaboom.getText().toString(); // get the text message on the text field
            kaboom.setText(null); // Reset the text field to blank

            printwriter = new PrintWriter(client.getOutputStream(), true);
            printwriter.write(messsage); // write the message to output stream

            printwriter.flush();
            printwriter.close();

            client.close();
        } 
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
4

2 回答 2

0

如果您的 EditText 需要 AsyncTask doInBackground 方法中的长计算结果,那么您应该在 asyncTask 的 onPostExcute 方法中更新此 editexts 值。希望能帮助到你。

于 2013-09-01T15:43:57.733 回答
0

创建一个字符串变量并将需要传输的值分配给另一个编辑文本,并将字符串作为参数传递给函数。

于 2013-09-01T15:20:23.867 回答