Issue
i'm trying to print the value of input of Activity 1 (class first) in the view.loadurl() of Activity (class MainActivity).
Here is my code:
Activity 1:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/urlYoutube"
android:layout_marginTop="95dp"
android:layout_below="@+id/textView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="@string/guia_txt" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn_download"
android:id="@+id/button"
style="@style/AppTheme"
android:textSize="23sp"
android:textStyle="normal"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
first.java:
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int str = R.id.urlYoutube;
Intent launchResult = new Intent(first.this, MainActivity.class);
launchResult.putExtra("dato", str);
startActivity(launchResult);
}
});
MainActivity.java:
WebView view = (WebView) this.findViewById(R.id.webkit);
view.getSettings().setJavaScriptEnabled(true);
view.getSettings().setBuiltInZoomControls(false);
view.getSettings().setSupportZoom(false);
view.setWebViewClient(new MyBrowser());
Bundle extras = getIntent().getExtras();
int str = extras.getInt("dato");
String s = "http://myurl.com/get.php?id=" + Integer.toString(str);
view.loadUrl(s);
This everytime print the same value.
What this print: http://myurl.com/get.php?id=2131492970
Can help me?
Thanks in advice.
Solution
I'm assuming you want to get the string inside that urlYoutube, right? for the EditText:
create the view like mUrlYoutube (or wherever):
mUrlYoutube = (EditText) findViewById(R.id.urlYoutube);
String str = mUrlYoutube.getText().toString();
What you're doing right now is to get the Resource ID int value from R ones the compiler does all the work.
When you have a resource, you must call it this way:
String str = getResource().getString(R.string.urlYoutube);
if int:
int str = getResource().getInteger(R.integer.urlYoutube);
Answered By - Mariano Zorrilla
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.