English 中文(简体)
多元 EditTextfield in a ListAdapter
原标题:Android Multiple EditText fields in a ListAdapter

我有一个屏幕(见照片),有人利用基地Adapter的习俗延伸,用GridView。

当用户进入EditText油田时,他们进入的文字可能会转移或完全消失。 我假定这一点与意见的循环有关,但我对清单编制者的理解不好。

最初,由于Manifest的入境和roid:windowSoftInputMode=“adjustPan”而对这些田地进行了罚款,但如果你ot忙地进行开发,则这些田地将转而去。

All I am looking to do is get some String data from the user. The Strings are stored in a global String array "strings[]". The strings array is updated by MyTextWatcher, which is just an extension of TextWatcher.

The code (attempts) to ensure that the TextWatchers always know the position of their EditText field within the grid. That way, the TextWatchers should always be updating strings[] with the correct index.

shows an example of the carnage

我完全有理由相信,这个问题源于我的看法:

public void initList()
{
    ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, R.layout.shape, strings)
    {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent)  {
            final ViewHolder holder;

            if (convertView == null  || convertView.getTag() == null)  {
                convertView = LayoutInflater.from(getContext()).inflate(R.layout.shape, null);

                holder = new ViewHolder();
                holder.text = (TextView) convertView.findViewById(R.id.shape_text);
                holder.image = (ImageView) convertView.findViewById(R.id.shape_image);
                holder.editText = (EditText) convertView.findViewById(R.id.shape_edittext);

                holder.editText.addTextChangedListener(new TextWatcher() {                      
                    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2){}
                    public void onTextChanged(CharSequence s, int start, int before, int count) {
                        if (gameType == SHAPES_ABSTRACT && before == 0 && count == 1) {
                            InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                            mgr.hideSoftInputFromWindow(holder.editText.getWindowToken(), 0);                               
                        }    
                    }
                    public void afterTextChanged(Editable s) {
                        strings[holder.ref]= s.toString(); 
                    }
                });

                convertView.setTag(holder);                    
            }
            else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.ref = position;
            holder.editText.setText(strings[position]);                             

            holder.image.setBackgroundResource(images[position]);

            if (gameType == SHAPES_ABSTRACT)
                holder.text.setText("Seq:");
            else
                holder.text.setVisibility(View.GONE);   

            return convertView;
        }
    };

    grid.setAdapter(listAdapter);
}
最佳回答

我再次以这种方式来形容这一点,就像在其他答复中一样。 你们 doing。 围绕许多参考资料。 然而,我认为这应当有助于:

Map<EditText, MyTextWatcher> watchers = new HashMap<EditText, MyTextWatcher>();

public View getView(int position, View convertView, ViewGroup parent)
{
    View MyView = convertView;
    if (MyView == null)
    {
        LayoutInflater li = getLayoutInflater();
        MyView = li.inflate(R.layout.shape, null);
    }

    EditText textbox = (EditText) MyView.findViewById(R.id.shape_edittext);

    textbox.setText(strings[position]);
    MyTextWatcher myTextWatcher = watchers.get(textbox);

    if(myTextWatcher == null)
    {
        myTextWatcher = new MyTextWatcher(position, textbox);
        watchers.put(textbox, myTextWatcher);
    }

    myTextWatcher.setIndex(position);

    ImageView image = (ImageView) MyView.findViewById(R.id.shape_image);
    image.setBackgroundResource(images[position]);

    TextView text = (TextView) MyView.findViewById(R.id.shape_text);
    text.setText("Seq:");

    return MyView;
}

这里的问题是,你创建了文本Watcher,将其添加到EditText上,但随后在一份名单中保留提及该文本,从而打破了EditText和文本Watcher之间的提及。

这种办法假定,EditText的等同物将比较,而不是比较价值。 如果是NOT,那么你需要提及所有EditText案,并做一个=比较,找到相应的数据。

我认为,这样做有更安全的途径,但给它一个枪声。

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签