R
R
redasya2017-10-11 07:20:43
Java
redasya, 2017-10-11 07:20:43

Java.Get int from EditText or are there other ways?

The essence is this, they gave the task, it is necessary that by pressing a button in the application, I receive data from the html page, I did it! BUT it is necessary that a person can enter a number (id), press the button, and get the text corresponding to this id. Here is the
package code com.example.android.fivecardview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.koushikdutta.async.future.FutureCallback;
import com.koushikdutta.ion.Ion;

public class MainActivity extends AppCompatActivity {
    Button button;
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        final int a = 3;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.button);
        textView = (TextView) findViewById(R.id.text1);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Ion.with(getApplicationContext())
                        .load("https://jsonplaceholder.typicode.com/posts/" + a)
                        .asString()
                        .setCallback(new FutureCallback<String>() {
                            @Override
                            public void onCompleted(Exception e, String result) {
                                textView.setText(result);
                            }
                        });
            }
        });

    }
}

As you can see everything works! Look, there is int a, and because its value is 3, the text with id = 3 is opened, and now the question is how to make int a change to the number that was entered in the EditText (well, or something like that) ??? I tried all your Ingeter.parseInt and getTexts, the application crashes stupidly....

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Mikhalev, 2017-10-11
@Endru9

Well and to look why to be painted? Yes, and in Google there is a lot of information on translating a string into a number.
And why actually use the int value if everything is passed to a string? Isn't it easier to create a string variable and pass it?
editText.getText().toString() to help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question