Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2771
  • Last Modified:

Refreshing edittext value in android

can i know to how refresh edittext value in  android, whenever i click  a button with a edittext value, some time it takes the old value in the editext
0
roy_sanu
Asked:
roy_sanu
  • 5
  • 4
1 Solution
 
dj_alikCommented:
edittext .invalidate();
0
 
roy_sanuAuthor Commented:
This  will not work
0
 
dj_alikCommented:
can you publish the source code of xml and java?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
roy_sanuAuthor Commented:
public class MainActivity extends Activity  
{
      private static final String TAG = MainActivity.class.getName();
      
      String appIdStr;
      String myApd;
      String s;
      
      EditTextStrVal;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            appIdStrVal = (EditText)findViewById(R.id.editText1);
      //      this.appIdStrVal.setOnClickListener(this);
      //      appIdStrVal.setOnClickListener(MainActivity.this);
       
                  
            Button submit = (Button) findViewById(R.id.Submit);
            submit.setOnClickListener(new OnClickListener() {

          public void onClick (View v) {
          
        
          EditText appIdStrVal = (EditText) findViewById (R.id.editText1);
        
        appIdStrVal.setText("");
      
          appIdStr = appIdStrVal.getEditableText().toString();
            

          String s = "Create module ASID=666, ACIN=231, CTSID=205";
          
           boolean banner = s.contains("Create Banner");
          
          
           if (banner)  {
          
                 String[] tokens = s.replace( "Create Banner ", "" ).split( ", " ) ;
                 Map<String, String> map = new HashMap<String, String>() ;
                      for( String token : tokens ){
                        String[] temp1 = token.split( "=" ) ;
                        map.put( temp1[0], temp1[1] ) ;
                      }  
                      s = map.get( "APID" );
                      myApid = s;
                   
           }
          
          
           else  {
                 boolean  banner= s.contains("Create banner");
                 String[] tokens = s.replace( "Create banner", "" ).split( ", " ) ;
                 Map<String, String> map1 = new HashMap<String, String>() ;
                      for( String token : tokens ){
                        String[] temp = token.split( "=" ) ;
                        map1.put( temp[0], temp[1] ) ;
                      }  
                      s = map1.get( "APID" );
                      myApid = s;
                 
           }
                      
      Toast toast1 = Toast.makeText(MainActivity.this, myApid , Toast.LENGTH_SHORT);
      toast1.show();
            
                  
          
          }

              });
      
      
            }
            
      }
activity-main.xml
0
 
roy_sanuAuthor Commented:
Trying to clear the edittext1  with appIdStrVal.setText(""); but it is not working . initally it will take the old value if one click the button twice it is working.
0
 
dj_alikCommented:
Let's make some clean for code:
can you work with public reference of  EditTextStrVal  not in click event.
Save the reference Oncreate for performance issue.

Did you mean that  text is changed (empty) only on second click all time or in first time?
0
 
roy_sanuAuthor Commented:
it works on the second click only not on the first click
0
 
dj_alikCommented:
Why you need this lines:
 appIdStrVal.setText("");

it always will be empty
appIdStr = appIdStrVal.getEditableText().toString
0
 
dj_alikCommented:
and
appIdStr = appIdStrVal.getEditableText().toString();

replace to

appIdStrVal.getText().toString();
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now