android - ActionBar with fragments accessing widgets from fragments crashes the app -


I have an activity (tabActivia.java) that contains a piece container in which there is a layout, with touch The action bar is clicked in. Now, in the menu of the action bar, I have a menu-option (a button) that saves content from pieces.

My problem is as follows: I have a fragment fragment_aloc.xml where I have an edit text with a textview and id = "edaloc", I get this edit from the Save button I want to click on (menu) I want to do this for all the pieces (get values ​​from those widgets which are located to save values ​​in the database).

  @ Override Public Boolean On Option Items (Manitem Item) {Switch (ITAT. ITMID) {Case R. .. // Here is the code that receives value from pieces}}   

But when I try to do this (click on the save button) I get an error:

4805-4805 / ro.myapp.app E / AndroidRuntime ?? Fundamental Removal: The main java.lang.NullPointerException.TabActivity.onOptionsItem selected (TabActivity.java:134)

and line (134) on ro.myapp.app in which this issue says: / P> Editing Text Adlocare = (Editing Text) SearchVBIID (RIDEdaloc);

I also tried to do this:

  EditText edalocare = (EditText) actionBar.getCustomView (). FindViewById (R.id.edaloc);   

The same error. The thing is that I'm watching the piece, and I'm watching the adite.

I repeat: My goal should be

Many pieces , with EditTexts and RadioGroups on them. Click in the menu, I want to get all the values ​​ and save them to a database in them.

Thanks Edit

So I'm just trying this code: now in my piece (java code):

  public square aloc_fragment increases the piece {@ Override Public View Creativity (Layout Inflator Inflight, View Group Container, Bundle Saved InstantState) {// Layout flyer to return to this piece in flat (R. Late Fragment_Aloc, Container, false); } Public string getEditValue (integer id) {EditText edu = (EditText) getView (). FindViewById (id); Return ""; }}   

And inside my activity, I try to reach the value of "edaloc" EditText like this:

  piece slice 1 = ( Piece) getFragmentManager () .findFragmentByTag ("aloc"); String val_aloc = fragment1.getEditValue (RID adeloc);   

But it does not work. (The tag of the piece has been declared inside the layout of the section) "Piece 1.getEditValue (R. deDeloc)";

Edit is the code for the activity (close the code for the action tab tab):

  public Class enhances tabactivity activity (fragment section tab1 = new aloc_fragment (); @ override protected form to zero (bundle saved instenstate) {super.ncre (savedinstenstate); setContentView (R.layout.activity_tab);}    

If your activity allows you to use widgets defined in your widget You try to do (in the layout of the piece), you can not do this by calling the action by findViewById () . You have to call this method with your piece.

  1. Define a public method on the squares classes / classes This method should return the value to your EditText . FindViewById () can be used safely because you have your EditText that section Are being reached within where it has been defined.

  2. As you make your pieces manually, you can create tags for each section as you make it. Store the tags of pieces created in your activity.

  3. When you need to get value from pieces, use the findFragmentByTag (string tag) method for each tag you have stored Then call the method you added in 1 point and get this type of value from EditText .

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -