Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Refreshing edittext value in android

Posted on 2013-01-16
9
Medium Priority
?
2,669 Views
Last Modified: 2013-01-21
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
Comment
Question by:roy_sanu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 18

Expert Comment

by:dj_alik
ID: 38785899
edittext .invalidate();
0
 

Author Comment

by:roy_sanu
ID: 38792442
This  will not work
0
 
LVL 18

Expert Comment

by:dj_alik
ID: 38792476
can you publish the source code of xml and java?
0
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

 

Author Comment

by:roy_sanu
ID: 38792498
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
 

Author Comment

by:roy_sanu
ID: 38792502
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
 
LVL 18

Expert Comment

by:dj_alik
ID: 38792545
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
 

Author Comment

by:roy_sanu
ID: 38792602
it works on the second click only not on the first click
0
 
LVL 18

Expert Comment

by:dj_alik
ID: 38792620
Why you need this lines:
 appIdStrVal.setText("");

it always will be empty
appIdStr = appIdStrVal.getEditableText().toString
0
 
LVL 18

Accepted Solution

by:
dj_alik earned 2000 total points
ID: 38792642
and
appIdStr = appIdStrVal.getEditableText().toString();

replace to

appIdStrVal.getText().toString();
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn different types of Android Layout and some basics of an Android App.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question