简体   繁体   English

如何将一个edittext的结果传递给另一个edittext?

[英]how to pass the result of one edittext to another edittext?

How do I pass the result of one edittext to another edittext? 如何将一个edittext的结果传递给另一个edittext? This is my example code of one edittext: 这是我的一个edittext的示例代码:

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

And I want the value of tv.setText(vis.toString()); 我想要tv.setText(vis.toString()); will be transferred to another one edittext which I will be using to be an input on my Asynctask (Server-Client communication). 将被传输到另一个编辑文本,我将使用该文本作为Asynctask(服务器-客户端通信)的输入。

Can anyone help me? 谁能帮我?

Asynctask: Asynctask:

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

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

If your EditText needs a result from a long calculation in AsyncTask doInBackground method then you should uptate this editexts value in onPostExcute method of asyncTask. 如果您的EditText需要AsyncTask doInBackground方法中的长时间计算结果,则应在asyncTask的onPostExcute方法中更新此editexts值。 Hope it helps. 希望能帮助到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将EditText输入从一个类传递到Android中的另一个类 - Pass an EditText input from one class to another in Android 如何在另一个活动的 Textview 中传递用户 EditText 输入 - How to pass users EditText input in a Textview in another activity 如何将多个edittext值传递到Arraylist中,然后将其发送到另一个活动? - How to pass multiple edittext values into a Arraylist and then send it to another activity? 如何将一个活动的edittext字符串传递给另一个活动中的方法? - How to pass an edittext string from an activity to a method in another activity? 如何将生成的字符串传递给EditText? - How to pass a generated string to an EditText? 从一种活动转移到另一种活动时,如何保持editText输入? - How to keep editText inputs when moving from one activity to another? 如何将 EditText 值从一个活动到另一个活动作为 int 获取到 go - How to get an EditText value to go from one activity to another as an int 如何将信息从一个活动的EditText传递到另一个活动,以将URL加载到该新活动的WebView中? - How do I pass info from one activity's EditText to another for the url to be loaded in that new activity's WebView? 如何在Android的第三个EditText中获得两个EditText的减法结果? - How to get the subtraction result of two EditText in third EditText for Android? 将 ListView 值传递给另一个 Activity 中的多个 EditText - Pass ListView values to multiple EditText in another Activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM