How can I convert 4digit number a single digit number in Android
<p>I had a edit text, in the edit text I used to enter a 4digit number and I have set some keys and value pair to 0-9 numbers. </p>

<p>So my question is when ever I enter a 4 number(any no of digits) in the edittext it should be converted into a single digit number so that the message in the <code>keyvalue</code> should appear.</p>

<p>This is my code:</p>

<pre><code>public class MainActivity extends Activity {

     String Sequence;
     Button buttonok;
     String UserEntreredNumber;
     HashMap&lt;String,String&gt; messagesMap = new HashMap&lt;String,String&gt;();
     String magicMessage;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final EditText Sequence = (EditText)this.findViewById(R.id.Sequence);    

        Sequence.setError("Input must be 4 digits");



        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setPositiveButton(" ok ",  new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {

                dialog.cancel();
          }
        });

        //create hash map

       populateList(); 

        //populate hash map with 0 to 9 key and values


        buttonok=(Button)this.findViewById(R.id.buttonok);
        buttonok.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                UserEntreredNumber = Sequence.getText().toString();
                magicMessage = messagesMap.get(UserEntreredNumber);

                builder.setMessage( magicMessage);
                builder.show();         
        }
    });     

}
    private void populateList() { 

       messagesMap.put("0", "Congratulations!!!, you have been selected."); 
       messagesMap.put("1", "Wow! your program just ran without errors!"); 
       messagesMap.put("2", "It's very hot in office"); 
       messagesMap.put("3", "Wow, what a building? It's awesome");
       messagesMap.put("4", "You got a calll");
       messagesMap.put("5", "There were no errors");
       messagesMap.put("6", "U have been shortlisted for the next round");
       messagesMap.put("7", "nice costume");
       messagesMap.put("8", "do u have any idea!");
       messagesMap.put("9", "Today is a bad day");    
    }   
}
</code></pre>
