The interface
public interface GameSelectedListener {
public void onGameSelectedListener(int gameID, Boolean isCustom);
}
Inside FragmentA in the on attach I set the gameSelectedListener in on attach.
public void onAttach(Activity activity)
{
super.onAttach(activity);
gameSelectedListener = (GameSelectedListener)activity;
}
In one part of the code some data is sent
gameSelectedListener.onGameSelectedListener(groupItems.get(groupPosition).iD, isCustom);
Main activity which implements the interface and calls a method in FragmentB
#Override
public void onGameSelectedListener(int gameID, Boolean isCustom) {
// TODO Auto-generated method stub`enter code here`
FB.setGameID(gameID, isCustom);
}
Inside Fragment B is the setGameID method which just sets some data inside that fragment.
public void setGameID(int gameID, Boolean isCustom)
{
this.gameID = gameID;
this.isCustom = isCustom;
}
With log statements (not shown here). The data generated by fragment A is successfully sent to main activity. I log the values of the variables in setGameID method of fragment B also appear correctly to that generated by fragment A.
However here is the problem
I get null pointer exceptions when using gameID and isCustom from the FragmentB. So I set some default values to check it and I noticed that the value change made in setGameID does not effect the global variables even though when logging the values in setGameID show the correct values. Note that these two variables are not changed anywhere else in the code. Just in setGameID method.
I don't know if this helps but my fragments are java fragments (not XML based)
In main activity I create an instance of Fragment B in order to call setGameID. Note I declare this in the global area only.
FragmentB FB = new FragmentB();
Heres how it looks so far
Activity A -> Fragment Transaction add Fragment A -> From Fragment A Button click-> fragment replace A with B
EDIT Added some more code: Issue could be here.
gameSelectedListener.onGameSelectedListener(groupItems.get(groupPosition).iD, isCustom);
fragment = FragmentB.newInstance();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(Container.getId(), fragment, tag);
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
I think the problem could well be here because I invoke the listener and then make a the Fragment B instance. Could this be it?
Use an EventBus instead of a listener! This design pattern mentioned in the official android docs is bullshit!
https://github.com/greenrobot/EventBus
class FragmentB extends Fragment {
private int id;
public static FragmentB newInstance(int id){
Bundle args = new Bundle();
args.putInt("id", id);
FragmentB frag = new FragmentB();
frag.setArguments(args);
}
public void onCreate(Bundle b){
super.onCreate(b);
this.id = getArguments().getInt("id);
}
}
When you replace Fragment A by Fragment B.
#Override
public void onGameSelectedListener(int gameID, Boolean isCustom) {
...// rest of the code
Bundle args = new Bundle();
args.putInt("id", gameID);
args.putBoolean("bool", isCustom);
FB.setArguments(args);
}
In Fragment B
int value = getArguments().getInt("id");
Related
I have a fragment that displays data from APIs, but i dont want to be calling apis everytime the fragment is called.. so am making api call from a different class and and calling a method in the fragment to update UI (textViews)
but am getting null exception for the textViews but data is 100% there
and if i try to hardcode textView.setText("Hello") it works..
one of the task of fragment is change ui !!! you must change ui in activity or fragment
you must use interface . your server class :
public class server {
.
.
.
public void callServer(IServerResponse iResponse){
.
.
.
iResponse.onResponse(//your data such as List or string or json and etc);
}
public interface IServerResponse{
// use parameter type as you want like List or string ,etc..
void onResponse(String data);
}
}
your fragment or activity implement your interface :
public class SomeFragment extends Fragment implements Server.IServerResponse{
....
#Override
public View onCreateView(...){
...
Server server=new Server();
server.callServer(this);
}
#Override
public void IServerResponse(String data){
textview.SetText(data);
}
}
You should create a FrameLayout in your activity
And use this code:
FragmentA newFragment = new FragmentA ();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.container, newFragment).commit();
and than set your text
String editValueName= editName.getText().toString();
String lastStatus = valueStatus.getText().toString();
newFragment .setText(editValueName, lastStatus);
Try for quick fix if it is working for the output of your desire
Make Textview static in class(youractivity) where textview is originated like
public static TextView textview;
And in fragment
if(youractivity.textView!=null){ youractivity.textView.setText("your desire text"); }
I have a database that provides an array of Strings, accessed from within a Fragment. I want these Strings to go back to the activity attached to the Fragment and set the titles of the tabs in a ViewPager. How can I do this?
This is how I want to do it:
Database String[] → Fragment → Attached activity's ViewPager → New
tabs
Edit: Here is my entire Activity and PagerAdapter code.
Here is my Fragment code
Suppose you have array of Strings and you want to send them to your activity from Fragment, make an interface like
public class MyFragment extends Fragment {
CustomStrings mCallback;
// Container Activity must implement this interface
public interface CustomStrings {
public void onStringRecieved(String[] stringss);
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
mCallback = (CustomStrings) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
And then simple use this when you need to send data
mCallback.onStringRecieved(yourStrings); //your data here
And then in your activity implement it
public class MainActivity extends Activity
implements MyFragment.CustomStrings{
...
public void onStringRecieved(String[] stringss) {
// Do something here to use these strings
Toast.makeText(getContext(), ""+strings, Toast.LENGTH_SHORT).show();
}
Hope this solves your problem, for more information refer this
I was trying to communicate between two fragments, but I'm just a beginner so I want to know if there is any solution not using interface....
If there are Fragment A, B, and their Activity:
Sending values from Fragment A to Activity
(In here, Fragment A is a current state)
Sending values from Activity to Fragment B
I know direct communication between two fragments is almost impossible,
but I don't think that makes me to use an interface.
Also, is there any method to use like putExtra() for fragment? I only know using Serializable.
Have a look at the Android deverlopers page: http://developer.android.com/training/basics/fragments/communicating.html#DefineInterface
Basically, you define an interface in your Fragment A, and let your Activity implement that Interface. Now you can call the interface method in your Fragment, and your Activity will receive the event. Now in your activity, you can call your second Fragment to update the textview with the received value
// You Activity implements your interface
public class YourActivity implements FragmentA.TextClicked{
#Override
public void sendText(String text){
// Get Fragment B
FraB frag = (FragB)
getSupportFragmentManager().findFragmentById(R.id.fragment_b);
frag.updateText(text);
}
}
// Fragment A defines an Interface, and calls the method when needed
public class FragA extends Fragment{
TextClicked mCallback;
public interface TextClicked{
public void sendText(String text);
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
mCallback = (TextClicked) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement TextClicked");
}
}
public void someMethod(){
mCallback.sendText("YOUR TEXT");
}
#Override
public void onDetach() {
mCallback = null; // => avoid leaking, thanks #Deepscorn
super.onDetach();
}
}
// Fragment B has a public method to do something with the text
public class FragB extends Fragment{
public void updateText(String text){
// Here you have it
}
}
You can communicate between fragments directly by using EventBus - send ordinary or sticky events by one fragment and subscribe to that event in another one.
If don't want message to be lost, use sticky events - it work as sticky Intent in Android. It will be around until it is removed by targer fragment or because another event is pending.
Yes you can transfer data between fragments using bundle like you do in Activity using putExtra
Bundle = bundle = new Bundle();
bundle.putString("key","value");
bundle.putSerializable("serialzedKey",SerializedValue);
FragmentTransaction fts = ((BaseActivity) mContext).getSupportFragmentManager().beginTransaction();
fragment.setArguments(bundle);
fts.add(R.id.fragmentHolder, fragment);
fts.addToBackStack(fragment.getClass().getSimpleName());
fts.commit();
In other fragment you can retrieve data using getArguments()
String key = getArguments().getString("key");
SerializedModel = getArguments().getSerializable("serialzedKey");
you can call a method from the parent activity class that calls a method from fragment B like ((YourActivity)getActivity()).callMethod(T yourData)
Take a look at my Github repo on using interfaces to communicate between fragments.
This is just a really simple example but displays the key concepts.
https://github.com/stoddayy/FragmentInteractionExample
I've found a ton of conflicting information regarding the proper way to restore application state when using Fragments embedded in Activities. Please let me know if my architecture is the problem because that is totally possible. My test Weather app is architected as follows.
The main activity "ReportsActivity" contains the fragment "ReportsFragment" (This is a list of the next 10 days of Weather Reports)
ReportsFragment has an onItemClickListener that launches a new Activity "WeatherDetailActivity" and passes it an intent which contains some JSON Data that I use to populate the Weather Detail UI. This data is then presented on a fragment that the WeatherDetailActivity manages.
My problem is, when the user presses the back button, the ReportsFragment has been destroyed so it runs through its full lifecycle. I've tried a number of techniques I've found online to load the activity's data from a bundle, but no matter what I've tried so far the Intents' Extras are null in the ReportsActivity's onCreate method. (Note: the reason I need to do this is to avoid firing off an API Call each time I open my main Activity which fetches weather data from Weather Underground).
I'm struggling determining what would be the best way to construct this app: Should I have a single activity that pushes and pops Fragments that it manages? Or are multiple activities that each manage their own fragments the standard practice?
At the moment here is how I'm attempting to save my application state onto the intent. I'm trying to save the state in onPostExecute from my AsyncTask so i'm on the main thread after i've fetched my results from the API Call:
#Override
protected void onPostExecute(Report[] result){
if (result != null){
ArrayList<String>reportsArrayList = new ArrayList<String>();
Gson jsonArray = new GsonBuilder().setPrettyPrinting().create();
for (int x = 0; x < result.length; x++){
reportsArrayList.add(jsonArray.toJson(result[x], Report.class));
}
mExtras.putStringArrayList(ReportsActivity.ReportsActivityState.KEY_ACTIVITY_REPORTS,reportsArrayList);
}
}
I then attempt to restore state from the ReportsActivity's onCreate Method:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reports);
if (savedInstanceState == null) {
Intent intent = getIntent();
mFragment = ReportsFragment.newInstance(intent
.getStringArrayListExtra(ReportsActivityState.KEY_ACTIVITY_REPORTS));
getFragmentManager().beginTransaction()
.add(R.id.container, mFragment).commit();
}
}
In all cases the StringArrayListExtra I'm trying to get from the intent return null.
This could very well be me trying to solve an Android problem with an iOS mindset, but is there not an easy way to just restore the main activity to what it was before I pushed the detail view?
I think it would be worth your while taking a look at EventBus.
Basically you can define a object holder of any kind, for example:
class WeatherData {
List<String> reports;
public WeatherData(List<String> reports) {
this.reports = reports;
}
}
Now, in an Activity or Fragment in which you wish to remember the state, or pass some state to another Activity or Fragment do:
// this removes all the hazzle of creating bundles etc
EventBus.getDefault().postSticky(new WeatherData(reports));
And any where in your code your wish to know the most recent WeatherData:
WeatherData weatherData = EventBus.getDefault().getSticky(WeatherData.class);
EventBus also has nice methods for event handling (button clicks, completion of long running processes, etc..)
The library can be found here: https://github.com/greenrobot/EventBus
And some more examples here: http://awalkingcity.com/blog/2013/02/26/productive-android-eventbus/
Some suggestions without using 3. part library:
1) Calling setRetainInstance(true) in your fragments onCreate method, what this should do is to persist public variables between instances.
Though it seems it does not work for fragments on the back stack: Understanding Fragment's setRetainInstance(boolean)
2) Hand the fragment data to your Activity, something like reading/updating ((YourActivity)getActivity()).someFragmentBundle, possibly save it in onSaveInstanceState of the Activity and retrieve it in onCreate. That is, having your Activity hold the data in-between instances.
3) You could also persist the data, saving it to a file or using SharedPreferences http://developer.android.com/training/basics/data-storage/index.html
This method has the advantage that it will enable restoring the data even after a complete kill of your app.
The Architectural question
Disclaimer: subjective opinion
I would generally say keep the Activity as 'slim' as possible, holding a range of related fragments.
Thus, having multiple Activities is fine but they should each manage a set of (or a single) related fragments that are relevant for the current Activity.
It just occurred to me to check out one of the Android Studio templates that Google Provides that I often overlooked. From Google's own templates, it appears clear that the preferred method for Master Detail Activities/Fragments is to have each Fragment Managed by their own activities (as I was attempting to achieve above).
(I should note that I was able to successfully achieve to flow that I wanted using a single Activitiy with multiple fragments and customizing the Animation and forcefully showing and hiding the up button.)
PersonListActivity.java
public class PersonListActivity extends Activity
implements PersonListFragment.Callbacks {
/**
* Whether or not the activity is in two-pane mode, i.e. running on a tablet
* device.
*/
private boolean mTwoPane;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_person_list);
if (findViewById(R.id.person_detail_container) != null) {
// The detail container view will be present only in the
// large-screen layouts (res/values-large and
// res/values-sw600dp). If this view is present, then the
// activity should be in two-pane mode.
mTwoPane = true;
// In two-pane mode, list items should be given the
// 'activated' state when touched.
((PersonListFragment) getFragmentManager()
.findFragmentById(R.id.person_list))
.setActivateOnItemClick(true);
}
// TODO: If exposing deep links into your app, handle intents here.
}
/**
* Callback method from {#link PersonListFragment.Callbacks}
* indicating that the item with the given ID was selected.
*/
#Override
public void onItemSelected(String id) {
if (mTwoPane) {
// In two-pane mode, show the detail view in this activity by
// adding or replacing the detail fragment using a
// fragment transaction.
Bundle arguments = new Bundle();
arguments.putString(PersonDetailFragment.ARG_ITEM_ID, id);
PersonDetailFragment fragment = new PersonDetailFragment();
fragment.setArguments(arguments);
getFragmentManager().beginTransaction()
.replace(R.id.person_detail_container, fragment)
.commit();
} else {
// In single-pane mode, simply start the detail activity
// for the selected item ID.
Intent detailIntent = new Intent(this, PersonDetailActivity.class);
detailIntent.putExtra(PersonDetailFragment.ARG_ITEM_ID, id);
startActivity(detailIntent);
}
}
}
PersonListFragment.java
public class PersonListFragment extends ListFragment {
/**
* The serialization (saved instance state) Bundle key representing the
* activated item position. Only used on tablets.
*/
private static final String STATE_ACTIVATED_POSITION = "activated_position";
/**
* The fragment's current callback object, which is notified of list item
* clicks.
*/
private Callbacks mCallbacks = sDummyCallbacks;
/**
* The current activated item position. Only used on tablets.
*/
private int mActivatedPosition = ListView.INVALID_POSITION;
/**
* A callback interface that all activities containing this fragment must
* implement. This mechanism allows activities to be notified of item
* selections.
*/
public interface Callbacks {
/**
* Callback for when an item has been selected.
*/
public void onItemSelected(String id);
}
/**
* A dummy implementation of the {#link Callbacks} interface that does
* nothing. Used only when this fragment is not attached to an activity.
*/
private static Callbacks sDummyCallbacks = new Callbacks() {
#Override
public void onItemSelected(String id) {
}
};
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public PersonListFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO: replace with a real list adapter.
setListAdapter(new ArrayAdapter<DummyContent.DummyItem>(
getActivity(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1,
DummyContent.ITEMS));
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// Restore the previously serialized activated item position.
if (savedInstanceState != null
&& savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
}
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// Activities containing this fragment must implement its callbacks.
if (!(activity instanceof Callbacks)) {
throw new IllegalStateException("Activity must implement fragment's callbacks.");
}
mCallbacks = (Callbacks) activity;
}
#Override
public void onDetach() {
super.onDetach();
// Reset the active callbacks interface to the dummy implementation.
mCallbacks = sDummyCallbacks;
}
#Override
public void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
// Notify the active callbacks interface (the activity, if the
// fragment is attached to one) that an item has been selected.
mCallbacks.onItemSelected(DummyContent.ITEMS.get(position).id);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (mActivatedPosition != ListView.INVALID_POSITION) {
// Serialize and persist the activated item position.
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
}
}
/**
* Turns on activate-on-click mode. When this mode is on, list items will be
* given the 'activated' state when touched.
*/
public void setActivateOnItemClick(boolean activateOnItemClick) {
// When setting CHOICE_MODE_SINGLE, ListView will automatically
// give items the 'activated' state when touched.
getListView().setChoiceMode(activateOnItemClick
? ListView.CHOICE_MODE_SINGLE
: ListView.CHOICE_MODE_NONE);
}
private void setActivatedPosition(int position) {
if (position == ListView.INVALID_POSITION) {
getListView().setItemChecked(mActivatedPosition, false);
} else {
getListView().setItemChecked(position, true);
}
mActivatedPosition = position;
}
}
PersonDetailActivity.java
public class PersonDetailActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_person_detail);
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
// savedInstanceState is non-null when there is fragment state
// saved from previous configurations of this activity
// (e.g. when rotating the screen from portrait to landscape).
// In this case, the fragment will automatically be re-added
// to its container so we don't need to manually add it.
// For more information, see the Fragments API guide at:
//
// http://developer.android.com/guide/components/fragments.html
//
if (savedInstanceState == null) {
// Create the detail fragment and add it to the activity
// using a fragment transaction.
Bundle arguments = new Bundle();
arguments.putString(PersonDetailFragment.ARG_ITEM_ID,
getIntent().getStringExtra(PersonDetailFragment.ARG_ITEM_ID));
PersonDetailFragment fragment = new PersonDetailFragment();
fragment.setArguments(arguments);
getFragmentManager().beginTransaction()
.add(R.id.person_detail_container, fragment)
.commit();
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
navigateUpTo(new Intent(this, PersonListActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
}
PersonDetailFragment.java
public class PersonDetailFragment extends Fragment {
/**
* The fragment argument representing the item ID that this fragment
* represents.
*/
public static final String ARG_ITEM_ID = "item_id";
/**
* The dummy content this fragment is presenting.
*/
private DummyContent.DummyItem mItem;
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public PersonDetailFragment() {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments().containsKey(ARG_ITEM_ID)) {
// Load the dummy content specified by the fragment
// arguments. In a real-world scenario, use a Loader
// to load content from a content provider.
mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
}
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_person_detail, container, false);
// Show the dummy content as text in a TextView.
if (mItem != null) {
((TextView) rootView.findViewById(R.id.person_detail)).setText(mItem.content);
}
return rootView;
}
}
So I'm trying to wrap my head around Android Fragments. If I put the following code in my MainActivity:
public void getMessage(Object obj) {
Log.wtf("My object: ", obj.toString());
}
and the following code in my fragment:
((NewNotificationRule)getActivity()).getMessage("Yah wohooo!");
I get the "Yah wohooo!" into my MainActivity. The thing is that this pushes that string from my fragment to my Activity, where I want it to work the other way around. The fragment just defines a couple EditTexts, so upon hitting the submit-button defined in the xml called by the MainActivity, I want the MainActivity to pull the information defined in the EditTexts within the fragment so that it can submit it into the DB. So to conclude: I want to pull something (R.id.myEditText to be precise) from within my MainActivity instead of pushing it from within the fragment.
Is there any way that I can pull the contents of an EditText from a fragment into an Activity? All tips are welcome, since I'm totally lost here..
One fast option (not sure if this is safe or recommended tho) is creating a class in your project with attributes needed to store info and instancing an object of this class in the MainActivity. Then, reference it from the fragment and fill in it the data you need to save (e.g. within an attribute EditText1Data or something) whenever the text is changed or introduced into the fragment's EditText. Then just store into the DB the data contained in the object you filled with the Fragment info. Place some default values to the atttributes in the constructor of this called class to avoid null stuff problems. This can help you easily transfer Data in both directions Activity<-->Fragments , even tho this mightmean you must be very careful since you can get null pointer exceptions.
//This is Your DataClass used to transfer Data between Activity and Fragment.
public class DataClass {
public String EditText1Value;
public String EditText2Value;
public DataManager()
{
EditText1Value="Default Text";
EditText2Value="Default Text";
}
}
//This is the MainActivityClass
public class MainActivity extends Activity{
//instance of the DataClass to be passed to fragments with the method getDataClass
public DataClass dataClass = new DataClass();
//Main Activity code goes here...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
}
//This method returns a reference to the DataClass Object
public DataClass getDataClass()
{
//Return this class instance object of the DataClass class
return (dataClass);
}
//Now this is the method to push data to DB, called whenever an activity button is pressed.
private boolean WriteToDB ()
{
//Suppose this receives a String
WritetoDB(dataClass.EditText1Value);
}
}
//And this is the Fragment that sends data through the DataClass Object
public class ExampleFragment extends Fragment {
//Used to reference MainActivityObject and store info
DataClass dataClass;
//Used to Reference Activity's EditTexts
private EditText editText1;
//TextWatcher used to detect the EditText Field Changes
private TextWatcher EditText1_Txtwtr;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View v = inflater.inflate(R.layout.whatever_layout, container, false);
editText1= (EditText)v.findViewById(R.id.idEditText1);
setHasOptionsMenu(true);
return v;
}
#Override
public void onResume ()
{
super.onResume();
//code...
//Get MainActivity's DataClass object reference.
dataClass= ((MainActivity)getActivity()).getDataClass();
//store info whenever you need to, not necessarily on each keystroke, and store it in the object, not in the DB
dataClass.EditText1Value = editText1.getText().toString();
// Also, to capture whenever a edittext changes, you can use a textwatcher.
EditText1_Txtwtr= new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3)
{}
#Override
public void afterTextChanged(Editable editable)
{}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3)
{
dataClass.EditText1Value = editText1.getText().toString();
}
}
//Asign TextWatcher to your Edit Text.
editText1.addTextChangedListener(EditText1_Txtwtr);
}
}