Numeric softkeypad appears and instantly changes to normal keypad

341 Views Asked by At

HI all I was looking for a little help with my numeric softkeypad and an EditText. I have an activity with basically a 2 column table which has 1 column editable via EditText. I want the numeric phone keypad to appear when an EditText is clicked. It does do this but it almost instantly switches to a normal keypad. Sometimes it switches a couple of times?? The view is inside a custom adapter which is modified code from this blog

There is an xml file for the activity but it isn't really used they are set up programmatically. The xml file contains a linearLayout, ListView and a blank textview and edittext.

public class MethodEditor extends ListActivity {

private ArrayList<String[]> thismethod = new ArrayList<String[]>();


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
   super.onCreate(icicle);
   Bundle extras = getIntent().getExtras().getBundle("scanparam");
   ArrayList<String> param = new ArrayList<String>();//{
   param = extras.getStringArrayList("PARAM");
   ArrayList<String> value = new ArrayList<String>();
   value = extras.getStringArrayList("VALUE");
      for (int i = 0;  i < length; i++){      
       thismethod.add(new String[]{param.get(i), value.get(i)});
    }
   setContentView(R.layout.method_editor);
   MethodEditorAdapter editorAdapter = new MethodEditorAdapter(this, thismethod ); 
   setListAdapter( editorAdapter );
}

Now the custom adapter

class MethodAdapterView extends LinearLayout {        
    public MethodAdapterView(Context context, 
            String[] strings ) {
        super( context );

       // this.setOrientation(HORIZONTAL);        
        LinearLayout.LayoutParams Params = 
            new LinearLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT);
        Params.setMargins(1, 1, 1, 1);

        TextView paramname = new TextView( context );
        paramname.setInputType(InputType.TYPE_CLASS_PHONE);
        paramname.setText(strings[0]);
        paramname.setTextSize(20f);
        paramname.setTextColor(Color.WHITE);
        addView( paramname, Params);       

        LinearLayout.LayoutParams Value = 
            new LinearLayout.LayoutParams(150, LayoutParams.WRAP_CONTENT);
        Value.setMargins(1, 1, 1, 1);

        EditText paramvalue = new EditText(context);

        paramvalue.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL );
          paramvalue.setRawInputType(InputType.TYPE_CLASS_PHONE);
          paramvalue.setText(strings[1]);
        paramvalue.setTextSize(20f );
        paramvalue.setTextColor(Color.BLACK); 

        addView( paramvalue, Value); 

    }

}

public class MethodEditorAdapter extends BaseAdapter {

private Context context;
private ArrayList<String[]>  scanparam;

public MethodEditorAdapter(Context context, ArrayList<String[]> scanparam ) { 
    this.context = context;
    this.scanparam = scanparam;
}


public View getView(int position, View convertView, ViewGroup parent) { 
    return new MethodAdapterView(this.context, scanparam.get(position) );
}

}

This should be straightforward stuff but I presume something is going wrong in the custom adapter. Any ideas anyone?

I think it is more to do with my phone's default settings of querty keyboard that messes it up. If I manually change the phone settings to phone keypad then it works. Can I do this automatically?

0

There are 0 best solutions below