0

im new in this. but i have private variable which is have static text

private static final String URL = "http://google.com";

. and i create edittext like this

                android:id="@+id/url"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:hint="@string/add_url"
                android:inputType="textUri" />

how can i set the private variable from the edittext above?

is it

private static final String URL = urledittext.value;

? thats how done in pascal. because im new for java.

Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47

1 Answers1

0

You have to do it like this:

private static final String URL = url.getText().toString();

Look that your EditText have the id url.

Of course, you have to reference your EditText before using the method .getText():

EditText url = (EditText) view.findViewById(R.id.url);

EDIT: You can have your URL variable created in the top of your Activity.

private static final String URL;

and in your onCreate() method use the code that I put above:

EditText url = (EditText) view.findViewById(R.id.url);
URL = url.getText().toString();

Now the value of your URL variable will be the same as the text on the EditText.

Francisco Romero
  • 12,787
  • 22
  • 92
  • 167