出现数字软键盘并立即更改为普通键盘

发布于 2024-12-17 17:54:21 字数 3080 浏览 3 评论 0原文

大家好,我正在寻找有关数字软键盘和 EditText 的一些帮助。我有一个活动,基本上有一个 2 列表,其中有 1 列可通过 EditText 进行编辑。我希望在单击 EditText 时显示数字电话键盘。它确实做到了这一点,但它几乎立即切换到普通键盘。有时会切换几次? 该视图位于自定义适配器内,该适配器是从 此博客

该活动有一个 xml 文件,但并未真正使用,它们是以编程方式设置的。 xml 文件包含一个 LinearLayout、ListView 以及一个空白的 textview 和 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 );
}

现在是自定义适配器

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) );
}

}

这应该是简单的事情,但我认为自定义适配器中出现了问题。 有人有什么想法吗?

我认为这更多地与我手机的默认键盘设置有关,这把它弄乱了。如果我手动将电话设置更改为电话键盘,那么它就可以工作。 我可以自动执行此操作吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文