I want to transfer data from an activity with edit texts to a fragment class with a list to only display the edit_name box. I want to be able to click a button in the activity class and for it to save all of the information and display only the edit_name box. Anyone have any idea how to do this?
            Asked
            
        
        
            Active
            
        
            Viewed 38 times
        
    3 Answers
0
            
            
        Basically you could use Intents to do this, here is an example :
https://stackoverflow.com/a/12739968/5552022
Otherwise, you could use a library like EventBus which handles the process pretty efficiently :
 
    
    
        Community
        
- 1
- 1
 
    
    
        Omar Aflak
        
- 2,918
- 21
- 39
0
            
            
                        // Create a new Intent object as container for the result
                final Intent data = new Intent();
                // Add the required data to be returned to the MainActivity
                data.putExtra(EXTRA_DATA, "Some interesting data!");
                // Set the resultCode as Activity.RESULT_OK to 
                // indicate a success and attach the Intent
                // which contains our result data
                setResult(Activity.RESULT_OK, data); 
                // With finish() we close the DetailActivity to 
                // return back to MainActivity
                finish();
 
    
    
        Graham
        
- 7,431
- 18
- 59
- 84
 
    
    
        Ege Kuzubasioglu
        
- 5,991
- 12
- 49
- 85
0
            
            
        You can tranfer your data via bundle:
From your activity use below code to addd data in bundle:
Bundle bundle = new Bundle();
bundle.putString("key", "your string");
// set Fragmentclass data as fragment arguments
YourFragment fobj = new YourFragment();
fobj.setArguments(bundle);
and in Fragment you can get your data:
String strtext = getArguments().getString("key");   
 
    
    
        Android Geek
        
- 8,956
- 2
- 21
- 35
