Solved

Refreshing edittext value in android

Posted on 2013-01-16
9
2,330 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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 500 total points
ID: 38792642
and
appIdStr = appIdStrVal.getEditableText().toString();

replace to

appIdStrVal.getText().toString();
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

First off, some of you reading this are already thinking there is an error in the title. It really should be Kindle Fire versus OTHER Android tablets. That's because the Amazon Kindle Fire IS an Android tablet. Well, it is and it's not. It's running…
A short article about a problem I had getting the GPS LocationListener working.
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…

776 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