0

我正在android上制作数独益智应用程序。这就是我到目前为止所做的
Text Adapter.java

    public class TextAdapter extends BaseAdapter {
    private Context mContext;
    int count = 81;
    int k = 1;
    private static EditText current = null;

    public TextAdapter(Context c) {
        mContext = c;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return 81;
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        final EditText editText;
        if (convertView == null) {
            editText = new EditText(mContext);
            editText.setLayoutParams(new GridView.LayoutParams(85, 85));
            editText.setPadding(8, 8, 8, 8);
        } else {
            editText = (EditText) convertView;
        }
        editText.setId(k);
        editText.setGravity(Gravity.CENTER);
        editText.setBackgroundResource(R.drawable.rectangle);
        InputFilter[] FilterArray = new InputFilter[1];
        FilterArray[0] = new InputFilter.LengthFilter(1);
        editText.setFilters(FilterArray);

        editText.setOnFocusChangeListener(new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View view, boolean hasFocus) {
                // TODO Auto-generated method stub
                editText.setInputType(InputType.TYPE_NULL);
                if (current != null) {
                    current.setBackgroundResource(R.drawable.rectangle);
                }
                if (hasFocus) {
                    current = (EditText) view;
                    editText.setBackgroundResource(R.drawable.rectangleblue);
                }
            }
        });

        return editText;
    }

    public static EditText getCurrentEditText() {
        return current;
    }

}

我想用 1-9 的数字随机填充一些编辑文本,但我不知道如何获取每个编辑文本的标识符/名称。这可能吗?如何?
我是android开发的新手。

4

1 回答 1

0

创建 EditText 时,将它们添加到父级。

parent.addView(editText);

每当您想获取已创建的 EditTexts 时,都可以遍历父级的子级:

Edittext tempET;
int tempID=0;
for(int i = 0 ; i < parent.getChildCount(); i++) {
     tempET=(EditText) parent.getChildAt(i);
     tempID=tempET.getId();
}
于 2013-10-25T16:05:36.693 回答