How do I pass info between fragments and activities with an EditText?
up vote
0
down vote
favorite
Ok so, I'm currently working on a school project, my app has three tabs in the first and the second one it has two different web views with the webs showing properly and in the third one it has two EditTexts for me to be able to change those webs. The problem comes when I try to find those EditTexts from the fragment and save the url. How could I do it properly?
public class WebpageSetter_Fragment extends Fragment {
EditText direccion1, direccion2;
Button cambiarUrl;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.set_webpage_fragment, container, false);
}
android android-fragments
add a comment |
up vote
0
down vote
favorite
Ok so, I'm currently working on a school project, my app has three tabs in the first and the second one it has two different web views with the webs showing properly and in the third one it has two EditTexts for me to be able to change those webs. The problem comes when I try to find those EditTexts from the fragment and save the url. How could I do it properly?
public class WebpageSetter_Fragment extends Fragment {
EditText direccion1, direccion2;
Button cambiarUrl;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.set_webpage_fragment, container, false);
}
android android-fragments
1
so, in simple words, you want to communicate between fragments, right?
– Touhidul Islam
Nov 11 at 11:09
Ok, I'll try to explain it simple. Three fragments in my main activity, two of them are web views with a default web showing properly on them, the third one has two edit texts for you tu be able to copy an url and show it in one of the two previos fragments. By now I have the first two fragments working but at the time I want to put the url I copied in the third fragment to show in one of the others it crashes.
– Jorge Hetfield
Nov 11 at 17:42
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Ok so, I'm currently working on a school project, my app has three tabs in the first and the second one it has two different web views with the webs showing properly and in the third one it has two EditTexts for me to be able to change those webs. The problem comes when I try to find those EditTexts from the fragment and save the url. How could I do it properly?
public class WebpageSetter_Fragment extends Fragment {
EditText direccion1, direccion2;
Button cambiarUrl;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.set_webpage_fragment, container, false);
}
android android-fragments
Ok so, I'm currently working on a school project, my app has three tabs in the first and the second one it has two different web views with the webs showing properly and in the third one it has two EditTexts for me to be able to change those webs. The problem comes when I try to find those EditTexts from the fragment and save the url. How could I do it properly?
public class WebpageSetter_Fragment extends Fragment {
EditText direccion1, direccion2;
Button cambiarUrl;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.set_webpage_fragment, container, false);
}
android android-fragments
android android-fragments
edited Nov 11 at 12:23
Alex Kolydas
161113
161113
asked Nov 11 at 10:47
Jorge Hetfield
1
1
1
so, in simple words, you want to communicate between fragments, right?
– Touhidul Islam
Nov 11 at 11:09
Ok, I'll try to explain it simple. Three fragments in my main activity, two of them are web views with a default web showing properly on them, the third one has two edit texts for you tu be able to copy an url and show it in one of the two previos fragments. By now I have the first two fragments working but at the time I want to put the url I copied in the third fragment to show in one of the others it crashes.
– Jorge Hetfield
Nov 11 at 17:42
add a comment |
1
so, in simple words, you want to communicate between fragments, right?
– Touhidul Islam
Nov 11 at 11:09
Ok, I'll try to explain it simple. Three fragments in my main activity, two of them are web views with a default web showing properly on them, the third one has two edit texts for you tu be able to copy an url and show it in one of the two previos fragments. By now I have the first two fragments working but at the time I want to put the url I copied in the third fragment to show in one of the others it crashes.
– Jorge Hetfield
Nov 11 at 17:42
1
1
so, in simple words, you want to communicate between fragments, right?
– Touhidul Islam
Nov 11 at 11:09
so, in simple words, you want to communicate between fragments, right?
– Touhidul Islam
Nov 11 at 11:09
Ok, I'll try to explain it simple. Three fragments in my main activity, two of them are web views with a default web showing properly on them, the third one has two edit texts for you tu be able to copy an url and show it in one of the two previos fragments. By now I have the first two fragments working but at the time I want to put the url I copied in the third fragment to show in one of the others it crashes.
– Jorge Hetfield
Nov 11 at 17:42
Ok, I'll try to explain it simple. Three fragments in my main activity, two of them are web views with a default web showing properly on them, the third one has two edit texts for you tu be able to copy an url and show it in one of the two previos fragments. By now I have the first two fragments working but at the time I want to put the url I copied in the third fragment to show in one of the others it crashes.
– Jorge Hetfield
Nov 11 at 17:42
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
Use this code
EditText direccion1, direccion2;
Button cambiarUrl;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.set_webpage_fragment,container,false);
direccion2 = view.findViewById(R.id.your_edittext_id);
//same for the other edittext
//If you have a button to get the text and set the website into webviews,then find the button ID in same way and then use setOnClickListener on the button and then do the stuff
return view;
}
This goes for any kind of view you want to find anywhere, if there's a View in some kind of container, consider for example a LinearLayout, you can find the views inside the LinearLayout using the same method, initialize the LinearLayout and then use
linearLayoutObject.findViewById(R.id.id_of_view_you_want_to_find);
Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
– Jorge Hetfield
Nov 11 at 11:05
If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code,if(editText.getText().toString()!=null){ your stuff}
, if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…
– Wedprakash Wagh
Nov 11 at 11:07
Post the error you're getting so that I'd understand what the actual problem is.
– Wedprakash Wagh
Nov 11 at 11:22
add a comment |
up vote
0
down vote
Make method in your parent activity and pass your data from your fragment to activity and then get that data from parent activity to any fragment, in your case every fragment is child of the same parent activity.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Use this code
EditText direccion1, direccion2;
Button cambiarUrl;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.set_webpage_fragment,container,false);
direccion2 = view.findViewById(R.id.your_edittext_id);
//same for the other edittext
//If you have a button to get the text and set the website into webviews,then find the button ID in same way and then use setOnClickListener on the button and then do the stuff
return view;
}
This goes for any kind of view you want to find anywhere, if there's a View in some kind of container, consider for example a LinearLayout, you can find the views inside the LinearLayout using the same method, initialize the LinearLayout and then use
linearLayoutObject.findViewById(R.id.id_of_view_you_want_to_find);
Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
– Jorge Hetfield
Nov 11 at 11:05
If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code,if(editText.getText().toString()!=null){ your stuff}
, if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…
– Wedprakash Wagh
Nov 11 at 11:07
Post the error you're getting so that I'd understand what the actual problem is.
– Wedprakash Wagh
Nov 11 at 11:22
add a comment |
up vote
0
down vote
Use this code
EditText direccion1, direccion2;
Button cambiarUrl;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.set_webpage_fragment,container,false);
direccion2 = view.findViewById(R.id.your_edittext_id);
//same for the other edittext
//If you have a button to get the text and set the website into webviews,then find the button ID in same way and then use setOnClickListener on the button and then do the stuff
return view;
}
This goes for any kind of view you want to find anywhere, if there's a View in some kind of container, consider for example a LinearLayout, you can find the views inside the LinearLayout using the same method, initialize the LinearLayout and then use
linearLayoutObject.findViewById(R.id.id_of_view_you_want_to_find);
Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
– Jorge Hetfield
Nov 11 at 11:05
If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code,if(editText.getText().toString()!=null){ your stuff}
, if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…
– Wedprakash Wagh
Nov 11 at 11:07
Post the error you're getting so that I'd understand what the actual problem is.
– Wedprakash Wagh
Nov 11 at 11:22
add a comment |
up vote
0
down vote
up vote
0
down vote
Use this code
EditText direccion1, direccion2;
Button cambiarUrl;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.set_webpage_fragment,container,false);
direccion2 = view.findViewById(R.id.your_edittext_id);
//same for the other edittext
//If you have a button to get the text and set the website into webviews,then find the button ID in same way and then use setOnClickListener on the button and then do the stuff
return view;
}
This goes for any kind of view you want to find anywhere, if there's a View in some kind of container, consider for example a LinearLayout, you can find the views inside the LinearLayout using the same method, initialize the LinearLayout and then use
linearLayoutObject.findViewById(R.id.id_of_view_you_want_to_find);
Use this code
EditText direccion1, direccion2;
Button cambiarUrl;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.set_webpage_fragment,container,false);
direccion2 = view.findViewById(R.id.your_edittext_id);
//same for the other edittext
//If you have a button to get the text and set the website into webviews,then find the button ID in same way and then use setOnClickListener on the button and then do the stuff
return view;
}
This goes for any kind of view you want to find anywhere, if there's a View in some kind of container, consider for example a LinearLayout, you can find the views inside the LinearLayout using the same method, initialize the LinearLayout and then use
linearLayoutObject.findViewById(R.id.id_of_view_you_want_to_find);
answered Nov 11 at 10:58
Wedprakash Wagh
11
11
Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
– Jorge Hetfield
Nov 11 at 11:05
If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code,if(editText.getText().toString()!=null){ your stuff}
, if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…
– Wedprakash Wagh
Nov 11 at 11:07
Post the error you're getting so that I'd understand what the actual problem is.
– Wedprakash Wagh
Nov 11 at 11:22
add a comment |
Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
– Jorge Hetfield
Nov 11 at 11:05
If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code,if(editText.getText().toString()!=null){ your stuff}
, if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…
– Wedprakash Wagh
Nov 11 at 11:07
Post the error you're getting so that I'd understand what the actual problem is.
– Wedprakash Wagh
Nov 11 at 11:22
Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
– Jorge Hetfield
Nov 11 at 11:05
Yeah I know that but when I do it and I try to find the edit text and exception comes out and it says the edit text is null. What I wanna do is if the edit text isn't null I wanna take that String and load it as a web view in another fragment.
– Jorge Hetfield
Nov 11 at 11:05
If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code,
if(editText.getText().toString()!=null){ your stuff}
, if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…– Wedprakash Wagh
Nov 11 at 11:07
If you have a button in your app to get the text from EditText, then in onClickListener of your button use this code,
if(editText.getText().toString()!=null){ your stuff}
, if you still get an error, then check if there's actually an EditText with the ID in your layout and if you want to check out how to pass data between different fragments, check this link stackoverflow.com/questions/16036572/…– Wedprakash Wagh
Nov 11 at 11:07
Post the error you're getting so that I'd understand what the actual problem is.
– Wedprakash Wagh
Nov 11 at 11:22
Post the error you're getting so that I'd understand what the actual problem is.
– Wedprakash Wagh
Nov 11 at 11:22
add a comment |
up vote
0
down vote
Make method in your parent activity and pass your data from your fragment to activity and then get that data from parent activity to any fragment, in your case every fragment is child of the same parent activity.
add a comment |
up vote
0
down vote
Make method in your parent activity and pass your data from your fragment to activity and then get that data from parent activity to any fragment, in your case every fragment is child of the same parent activity.
add a comment |
up vote
0
down vote
up vote
0
down vote
Make method in your parent activity and pass your data from your fragment to activity and then get that data from parent activity to any fragment, in your case every fragment is child of the same parent activity.
Make method in your parent activity and pass your data from your fragment to activity and then get that data from parent activity to any fragment, in your case every fragment is child of the same parent activity.
answered Nov 19 at 14:15
Taha wakeel
916
916
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247972%2fhow-do-i-pass-info-between-fragments-and-activities-with-an-edittext%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
so, in simple words, you want to communicate between fragments, right?
– Touhidul Islam
Nov 11 at 11:09
Ok, I'll try to explain it simple. Three fragments in my main activity, two of them are web views with a default web showing properly on them, the third one has two edit texts for you tu be able to copy an url and show it in one of the two previos fragments. By now I have the first two fragments working but at the time I want to put the url I copied in the third fragment to show in one of the others it crashes.
– Jorge Hetfield
Nov 11 at 17:42