有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java EditText正在将自身复制到另一个EditText字段

现在,当我更改字段并打开另一个可扩展列表时,它会更改字段

Image

我的可扩展列表适配器

public class ExpandableListAdapter extends BaseExpandableListAdapter {

    private static final String LOG_TAG = "EXPANDABLE_LIST_ADAPTER_LOG";
    private Context _context;
    private List<String> _listDataHeader; // header titles
    // child data in format of header title, child title
    private HashMap<String, List<String>> _listDataChild;

    public ExpandableListAdapter(Context context, List<String> listDataHeader,
                                 HashMap<String, List<String>> listChildData) {
        this._context = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
        Log.i(LOG_TAG,"Child:"+listChildData+" header:"+listDataHeader);
    }

    @Override
    public Object getChild(int groupPosition, int childPosititon) {
        Object obj = this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .get(childPosititon);
        Log.i(LOG_TAG,"GroupPos:"+groupPosition+" childPos:"+childPosititon+" EdTex:"+obj);
        return obj;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public View getChildView(int groupPosition, final int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {

        final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_item, null);
        }

        EditText txtListChild = (EditText) convertView
                .findViewById(R.id.lblListItem);

       // txtListChild.setText(childText);
        txtListChild.setHint(childText);


        Log.i(LOG_TAG,"GroupPos:"+groupPosition+" childPos:"+childPosition+" text:"+txtListChild.getText());
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        String groupS = this._listDataHeader.get(groupPosition);

                int size =this._listDataChild.get(groupS)
                .size();
        Log.i(LOG_TAG,"Group:"+groupS+" grouppos:"+groupPosition+" size:"+size );
        return size;
    }
    @Override
    public Object getGroup(int groupPosition) {
        return this._listDataHeader.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return this._listDataHeader.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        String headerTitle = (String) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_group, null);
        }

        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.lblListHeader);
        lblListHeader.setTypeface(null, Typeface.BOLD);
        lblListHeader.setText(headerTitle);

        return convertView;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
    }

我还意识到,当键盘打开时,它会删除字段,或者使其消失,就像它正在创建另一个EditTexts.实例一样

第一个问题通过将stable ID设置为true得到了解决,我发现如果有人愿意将这些问题关联起来,这可能会很有用

The first problem got fixed by setting stable ids to true

@Override
public boolean hasStableIds() {
    return true;
}

共 (0) 个答案