How do I open different different URL stores in different different buttons. I'm just creating a separate activity that contains web view .
For example, one button contains links of Google. Another is containing links of Facebook, and another is Gmail.
Now I don't want to create separate activity for each click - I just want to create a activity that contains web view and when someone clicks the button they get inside this activity and the provided link will open with custom loading view
Help would be appreciated.
just create the method in the activity in which u have to show webView, which takes a string as a input and use this string in place of URL of webView,
call this function in the onClick of each button and pass the URL of desired website as parameter, do this for all the buttons
You can send the url of the website to the webview activity using intent and receive them accordingly!on each button click add you
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent=new Intent(this, webview.class);
intent.putExtra("URL","your url");
startActivity(intent);
}
});
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent=new Intent(this, webview.class);
intent.putExtra("URL","your url2");
startActivity(intent);
}
});
on your weview activity recive these urls and fire your webview as follows
String url=getIntent().getExtras().getString("URL");
Related
So, I am basically building an expense tracker app. I have successfully implemented Recycleview which contains Transactions' history. Now, what I am trying to achieve is to use an arrow imageview in the recycleview which will forward me to another activity when it is clicked. Any help will be appreciated on it.
in your adapter class inside onBindViewHolder method add
holder.img.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(context, OtherActivity.class);
context.startActivity(intent);
}
});
I am developing an app that consist of login-register app . In my login activity i have 2 buttons: LOGIN and REGISTER .The Register button is used to redirect you from login activity to register activity . The app works fine till I press once again . The app stops working.
final Button button = (Button) findViewById (R.id.button);
button.setOnClickListener (new View.OnClickListener(){
#Override
public void onClick (View v){
Intent launchactivity = new Intent (Login.this,Register.class);
startActivity (launchactivity);
});
try to change from Login.This to getApplicationContext()
public void onClick (View v){
Intent launchactivity = new Intent (getApplicationContext(),Register.class);
startActivity (launchactivity);
});
remove you login.this and add getApplicationContext()
I am developing an android app and in that i want to hyperlink the youtube video by button so that when i click that button a particular url will open which i provide to it. I want to build many buttons so also tell how to hyperlink a button with another button.
Help me out.
You can set an onClickListener on your button which will start the Intent:
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com/"));
startActivity(i);
}
});
I need to link the button with the page (not the main page) like when I click on the button to go to the page for example (location page)?
private void setupLocationPageButton() {
Button LocationPageButton = (Button) findViewById(R.id.btnLocationPage);
LocationPageButton.setOnClickListener(new View.OnClickListener()
If your goal is to open another activity this is what you are going to want to do.
In your xml file you are going to want something like this
...
<Button
android:id="#+id/activity_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onButtonClicked"
android:text="#string/text_of_button" />
...
Then in your activity you want
public void onButtonClicked(View view) {
Intent intent = new Intent(this, OtherActivity.class);
startActivity(intent);
}
what i think you trying to do: is when you click on button it's change the MainActivity
Button LocationPageButton = (Button) findViewById(R.id.btnLocationPage);
LocationPageButton.setOnClickListener(new View.OnClickListener({
public void onClick(View _view) {
Intent i = new Intent(MainActivity.this,TheActivityTheclassNameYouWannGoTo.class);
startActivity(i);
}
}));
but first you have to creat activity and class inherit Activity like MainActivity
initialize the class in AndroidMainfest.xml
i hope this help you
You can use fragment, each fragment contains a specific page, see this for Android fragment.
I found this code very usefull to get from one activity to the other but the problem is, that I don't see where the destination is mentioned. I would really appreciate it if some one pointed out how to change the destination.
Here is the code:
Button getTaxi = (Button) findViewById(R.id.GetTaxi);
getTaxi.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View view) {
final Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
}
});
The respective part in the xml:
<Button
android:id="#+id/GetTaxi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="GetTaxi" >
</Button>
Thank you very much in advance!
Actually, the code that executes on the Button's click states that your Activity (which is a sub-activity here by the way) has done its job and now finishes with the result code RESULT_OK. It means that there was another Activity that has started this actual Activity for some kind of result. So, when you'll click the Button your Activity will finish. To start some other Activity on the Button's click you should create an Intent, specifying explicitly the Activity you want to start, or just the action you want to perform over some data, letting the Android resolve the final Activity for you. Then you should call startActivity(), passing in the Intent you've created. Hope this helps.
You can use something like this:
Button getTaxi = (Button) findViewById(R.id.GetTaxi);
getTaxi.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(final View view) {
Intent intent = new Intent();
intent.setClass(this, GetTaxiActivity.class);
startActivity(intent);
//call finish() if the current activity is something like a loading page
}
});
The code piece above which you mentioned is a sub-activity which is called using
StartActivityForResult();