EditText.SetText()改变了我softkeyboard输入类型的自定义适配器 [英] EditText.SetText() changes my softkeyboard input type in a custom adapter

查看:175
本文介绍了EditText.SetText()改变了我softkeyboard输入类型的自定义适配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是自定义的基本适配器来实现customListView。 ListView控件类(延伸的ListView)在主要活动鳍状肢flipper.addView(mListView)内使用。

I am using a custom base adapter to implement a customListView. The listView class (extends ListView) is used within a flipper flipper.addView(mListView) in the main activity.

列表视图中有3种类型的行。
第一届在列表中是微调一排,未来2与行的EditText文本的地方便被输入。第3行及以后都与在它具有数一个EditText相同。
 我想让它这样,当我点击文本版本softkeypad将只有文本和数字版的手机键盘出现。结果
它们显示确定,但问题是当你点击一个EditText,在softkeyboard弹出精细的电话号码格式。
这是所有的设置和值以内getView()设置但是当softkeyboard在手机格式getView弹出()被调用一次(逻辑),但只要它击中文本类型EditTexts键盘类型切换回文本输入1 。它将不能容易地后转回到一个电话样式显示。该视图似乎跳来跳去,并努力把重点放在我的EditText希望
我真的在这里丢失,无法想出解决办法。
以下是code的2个主要位。

The list View has 3 types of rows. The 1 st in the list is a row with spinner, the next 2 are rows with edittext where text is inputed. The 3rd row and beyond are all the same with an edittext that has numbers in it. I wanted to make it so that when I click on the text version the softkeypad will appear with the text only and for the number version the phone keypad.
They display ok but the problem comes when you click on an edittext, the softkeyboard pops up fine in the phone format. It is all setup and values set within getView() but when the softkeyboard pops up in the phone format getView() gets called again (logical) but as soon as it hits 1 of the text type EditTexts the keyboard type switches back to text input. It will cannot easily be turned back to a phone style display after that. The view appears to be jumping around and struggling to focus on the EditText I want I am really lost here and can't figure this out. Here are the 2 main bits of code.

public class MethodEditorAdapter extends BaseAdapter{

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

private LayoutInflater mInflater; 

public MethodEditorAdapter(Context context, ArrayList<String[]> scanparam ) { 
    super();
    this.scanparam = scanparam;
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

}
@Override
public long getItemId(int position) {
    int i = 0;
    if(position == 0) i = 0;
    if(position ==1) i = 1;         
    if(position == 2)i = 1;
    if (position > 2)i = 2;
    return i;
}
@Override
public int getViewTypeCount() {
    return 3;
}

@Override
public int getItemViewType(int position) {
    int i = 0;
    if(position == 0) i = 0;
    if(position ==1) i = 1;         
    if(position == 2)i = 1;
    if (position > 2)i = 2;
    return i;
}

public View getView(int position, View convertView, ViewGroup parent) { 

    Formatnames(position);
    View rowView = convertView;
    ViewHolder holder = null;
    int type = getItemViewType(position);

    if (rowView == null ) {

        holder = new ViewHolder();
        switch (type) {
        case 0:
            rowView = mInflater.inflate(R.layout.method_editor_row_spin, null);
            holder.paramname = (TextView) rowView.findViewById(R.id.techniquetag);
            holder.techniquespinner = (Spinner) rowView.findViewById(R.id.techniquespinner);
            break;
        case 1:
            rowView = mInflater.inflate(R.layout.method_editor_row_text, null);
            holder.paramname = (TextView) rowView.findViewById(R.id.paramnameT);
            holder.paramvalue = (EditText) rowView.findViewById(R.id.paramvalT);
            break;
        case 2:
            rowView = mInflater.inflate(R.layout.method_editor_row_number, parent, false);
            holder.paramnameNum = (TextView) rowView.findViewById(R.id.paramnameN);
            holder.paramvalueNum = (EditText) rowView.findViewById(R.id.paramvalN);
            break;
        }
        rowView.setTag(holder);


    }else {
        holder = (ViewHolder) rowView.getTag();
    }

    setSelectedPosition(position);


    switch (type) {
    case 0:
        holder.paramname.setText(namestg + " " + nd);
        holder.techniquespinner.setSelection(Integer.valueOf(scanparam.get(position)[1]));
        break;
    case 1:
        holder.paramname.setText(namestg + " " + nd);
        holder.paramvalue.setText(scanparam.get(position)[1]);
        break;
    case 2:
    holder.paramnameNum.setText(namestg + " " + nd);
    holder.paramvalueNum.setText(scanparam.get(position)[1]);
    }

    return rowView;
}

static class ViewHolder {
    public TextView paramname;
    public EditText paramvalue;
    public Spinner techniquespinner;
    public TextView paramnameNum;
    public EditText paramvalueNum;

}

在主视图

public class MethodEditorView extends ListView {

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

public MethodEditorAdapter editorAdapter;

private ListView mListView;

private Context mContext;

public MethodEditorView(Context context, ArrayList<String[]> methodlist) { 
    super(context);
    // TODO Auto-generated constructor stub
    this.thismethod = methodlist;
    mContext = context;enter code here
initview(context);
}

 private void initview(Context context){
    editorAdapter = new MethodEditorAdapter(context, thismethod );
    this.setAdapter(editorAdapter);

 }

}

在XML,对不起,我不能正确插入。这是对数型

the xml, sorry I couldn't insert it properly. this is for the number type.

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="fill_parent" android:id="@+id/methodrownumber">
    <TextView android:layout_height="wrap_content" android:layout_weight="1" android:textSize="16sp" android:textStyle="bold" android:id="@+id/paramnameN" android:layout_width="fill_parent" android:padding="5dp"></TextView>
    <EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="16sp" android:layout_weight="1" android:id="@+id/paramvalN" android:imeOptions="actionNext" android:inputType="phone" android:focusable="true" android:focusableInTouchMode="true" android:clickable="true"></EditText>

推荐答案

让我为您节省大量的头痛在你的列表视图中的EditText。不这样做。我花了超过一个星期试图获得的EditText在ListView不回收的投入,以确保正确的输入是正确的领域,当你onresume。我会建议做一个tablelayout看起来像在一天结束的一个ListView滚动视图。只要你没有行的数量庞大,这将工作,并运行良好。现在,如果让我们说你有100行,不会是pretty。

Let me save you a lot of headache with the edittext in your listview. Don't do it. I spent well over a week trying to get edittext in a listview to not recycle inputs, to make sure the right input is in the right field when you onresume. I would recommend making a scroll view with a tablelayout that looks like a listview at the end of the day. As long as you don't have a huge number of rows this will work and run fine. Now if lets say you have 100 rows, not gonna be pretty.

    public class inputpage extends Activity implements OnClickListener{

        public TableLayout tl;
        static Map<Integer, String> inputValues = new LinkedHashMap<Integer, String>();
        private dbadapter mydbhelper;
        public static int editCount;
        private PopupWindow pw;
        public Cursor cursor;
        private ArrayList<EditText> m_edit = new ArrayList<EditText>();

        @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        mydbhelper = new dbadapter(this);
        mydbhelper.open();
        setContentView(R.layout.tablelayout);
        tl=(TableLayout) this.findViewById(R.id.table);
        getCursor();
        editCount = cursor.getCount();
        buildRow();

        View footer = getLayoutInflater().inflate(R.layout.footer_layout, null);
        tl.addView(footer);





        }
//This lets me get a cursor so I can settext on my textviews
        public void getCursor(){
        if(main.quickStart == "Cate"){
            cursor = mydbhelper.getUserWord();
        }...

            //add my rows in a loop based off how many items my cursor brought back
        public void buildRow(){
            //params for my different items
            LayoutParams textparam = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT, .30f);
            LayoutParams editparam = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT, .70f);
            textparam.setMargins(2, 2, 2, 2);
            editparam.setMargins(2, 2, 2, 2);
            editparam.gravity=17;
            LayoutParams rowparam = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
            cursor.moveToFirst(); //make sure cursor starts at beginning
            for (int i = 0; i < editCount; i++){
                TableRow tr = new TableRow(this);
                tr.setLayoutParams(rowparam); 

                //textview
                TextView tv=new TextView(this);
                tv.setLayoutParams(textparam);
                tv.setText(cursor.getString(cursor.getColumnIndex("userword")));
                tv.setTextSize(35f);
                tv.setGravity(Gravity.CENTER);
                tv.setWidth(175);
                tv.setTextColor(getResources().getColor(R.color.black));
                tr.addView(tv);

                //edittext
                EditText edit = new EditText(this);
                edit.setLayoutParams(editparam);
                tr.addView(edit);
                edit.setGravity(Gravity.LEFT);
                edit.setId(editCount);
                m_edit.add(i, edit);
                edit.setText("");

                cursor.moveToNext();
                tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
            }}

希望这有助于并为您节省了不少麻烦。 BTW我建什么我可以用XML(tablelayout,页脚等),只是通过Java使我的表行。

Hope this helps and saves you a lot of trouble. BTW I build what I can in xml (tablelayout, footer etc) and just make my table row via java.

这篇关于EditText.SetText()改变了我softkeyboard输入类型的自定义适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆