Send string parameter in Activity to Fragment On Android

This time I will discuss how do I send a string parameter of activity to fragment the turn layout (Intent).  I experienced this problem just now because I have just started using a fragment in my activity.

What is the fragment?

Fragment basically like activity that handle a layout, but the difference is the fragment can not walk alone fragment need activity to show a component.

We further discussed how to send a string parameter of activity to another activity that use fragment.

So I have a second activity that one without the other fragment by fragment, on the Activity 1 is currently set at the event onclick button perform as usual intent.

Intent intent = new Intent(Activity1.this, Activity2.class);
intent.putExtra("valueString", message);
startActivity(intent);

Kemudian pada Activity2 getting value string dari Activity1.

Intent intent = getIntent();
String strValue = intent.getStringExtra("valueString");

And to send the String parameter value to add syntax fragment such as the following syntax previous intent.

FragmentClass classFragement = new FragmentClass ();
Bundle bundle = new Bundle();
bundle.putString("valueString", strValue);
classFragement .setArguments(bundle);

And for the class fragment add the following syntax.

Bundle bundle = getArguments();
String selected = getActivity().getIntent().getStringExtra("valueString");
textValue.setText(selected);

In this tutorial I show you the results of parameters in a EditText that I named textValue.

okay so this tutorial may be useful: D

 

 

Test Driven Development (TDD)

What is TDD?  TDD (Test Driven Development) is a concept of application development where scripts for testing the application is made earlier than the main program code. Script is meant here is a program code that tests to test the parameter, the value of output produced by a function.

why should use TDD? 

If you have a web development team then the team member you commit the modules they have created by using version control (ex : git). You are sure that the modules they created is going well and there is no error. However, how do you know if they make the module does not cause error module / other existing class? whether you will check his one-on-one for each of the modules? What if there are many (tens to hundreds) modules in your application? what if everyone in your development team commit more than once in a day.

using TDD you do not need to check one by one for each module. You just stay the execution of test scripts that have been made previously. With one whole test script execution that there is going to run your fund will determine more quickly which modules I needed to be fixed.