Solved

Refreshing edittext value in android

Posted on 2013-01-16
9
2,233 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
Comment Utility
edittext .invalidate();
0
 

Author Comment

by:roy_sanu
Comment Utility
This  will not work
0
 
LVL 18

Expert Comment

by:dj_alik
Comment Utility
can you publish the source code of xml and java?
0
 

Author Comment

by:roy_sanu
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:roy_sanu
Comment Utility
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
Comment Utility
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
Comment Utility
it works on the second click only not on the first click
0
 
LVL 18

Expert Comment

by:dj_alik
Comment Utility
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
Comment Utility
and
appIdStr = appIdStrVal.getEditableText().toString();

replace to

appIdStrVal.getText().toString();
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction Everyone is using a smartphone these days. Contacts, messages, applications, documents, bookmarks, pictures, videos and other stuff which you created and are present only on your device come under the umbrella called “Personal Data”.…
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now