Listview android中的UI故障

Listview android中的UI故障,android,listview,android-viewholder,Android,Listview,Android Viewholder,我正在实现一个ListView,在大列表中快速滚动时会出现这个小故障。我使用的是ViewHolder模式 [![ListView中的UI故障][1][1] [1] : getView: public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(this.get

我正在实现一个ListView,在大列表中快速滚动时会出现这个小故障。我使用的是ViewHolder模式

[![ListView中的UI故障][1][1]

[1] :

getView:

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

    if (convertView == null) {
        convertView = LayoutInflater.from(this.getContext())
                .inflate(mResource, parent, false);

        viewHolder = new ViewHolder();
        viewHolder.titleView = (TextView) convertView.findViewById(R.id.sheet_name_text_view);
        viewHolder.rowsCount = (TextView) convertView.findViewById(R.id.rows_count_text_view);
        viewHolder.selectMessage = (TextView) convertView.findViewById(R.id.row_info_text);

        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }

    final ImportedTable item = getItem(position);
    if (item != null) {
        viewHolder.titleView.setText(item.getTableName());
        int columnsCount = 0;
        for (boolean isSelected : item.getSelectedColumns()) {
            if (isSelected) {
                columnsCount++;
            }
        }
        viewHolder.rowsCount.setText(context.getString(R.string.label_rowscounttext, (item.getRecordsCount() - item.getHeaderRow()), columnsCount));
    }

    final CheckBox isSelectedForImport = (CheckBox) convertView.findViewById(R.id.import_table_list_toggle_button);
    RelativeLayout checkboxLayout = (RelativeLayout) convertView.findViewById(R.id.import_table_list_toggle_layout);
    checkboxLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            isSelectedForImport.performClick();
        }
    });
    final TextView selectMessage = (TextView) convertView.findViewById(R.id.row_info_text);
    isSelectedForImport.setChecked(item.isSelected());
    if (!isSelectedForImport.isChecked()) {
        convertView.setClickable(true);
        viewHolder.titleView.setTextColor(Color.parseColor("#8A000000"));
    } else {
        convertView.setClickable(false);  viewHolder.titleView.setTextColor(Color.parseColor("#DE000000"));
    }
    isSelectedForImport.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (((ImportActivity) context).getNewApplication().hasChildren(item.getSheetId(), item.getTableId()) && !isSelectedForImport.isChecked()) {

                isSelectedForImport.setChecked(true);
                AlertDialog.Builder builder = new AlertDialog.Builder(context);
                final AlertDialog dialog;

                builder.setMessage(context.getString(R.string.importapplication_appscreen_label_lookupwarningmessage));
                builder.setPositiveButton(context.getString(R.string.ui_label_continue), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        for (int i = 0; i < item.getColumnType().size(); i++) {
                            removeLookups(item.getSheetId(), item.getTableId(), i);

                        }
                        isSelectedForImport.setChecked(false);
                        item.setSelected(false);
                        dialog.dismiss();
                    }
                });

                builder.setNegativeButton(context.getString(R.string.ui_label_dontcontinue), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                dialog = builder.show();

                notifyDataSetChanged();
            } else if (!isSelectedForImport.isChecked()) {
                item.setSelected(isSelectedForImport.isChecked());
                notifyDataSetChanged();
            } else {
                if (isSelectedForImport.isChecked()) {
                    for (int i = 0; i < item.getColumnType().size(); i++) {
                        if (item.getSelectedColumns().get(i) && item.getColumnType().get(i).equals("SINGLE_LOOKUP")) {
                            enableParents(item.getSheetId(), item.getTableId(), i);
                        }
                    }
                    notifyDataSetChanged();
                }
                item.setSelected(isSelectedForImport.isChecked());
            }
            mCallback.onTableSelectionToggle();
        }
    });

    if (((ImportActivity) context).getNewApplication().hasChildren(item.getSheetId(), item.getTableId())) {
        Set<String> children = ((ImportActivity) context).getNewApplication().getChildTableNames(item.getSheetId(), item.getTableId());
        Iterator<String> childIterator = children.iterator();
        String childrenString = childIterator.next();
        while (childIterator.hasNext()) {
            childrenString += ", ";
            childrenString += childIterator.next();
        }
        selectMessage.setText(context.getString(R.string.label_importlookupchildrentext) +" "+ childrenString);
        selectMessage.setVisibility(View.VISIBLE);

    } else {
        selectMessage.setVisibility(View.GONE);
    }

    return convertView;
}
public View getView(int位置、视图转换视图、视图组父视图){
if(convertView==null){
convertView=LayoutInflater.from(this.getContext())
.充气(mResource、parent、false);
viewHolder=新的viewHolder();
viewHolder.titleView=(TextView)convertView.findViewById(R.id.sheet\u name\u text\u view);
viewHolder.rowsCount=(TextView)convertView.findViewById(R.id.rows\u count\u text\u view);
viewHolder.selectMessage=(TextView)convertView.findViewById(R.id.row\u info\u text);
convertView.setTag(viewHolder);
}否则{
viewHolder=(viewHolder)convertView.getTag();
}
最终导入表项目=获取项目(位置);
如果(项!=null){
viewHolder.titleView.setText(item.getTableName());
int columnsunt=0;
for(布尔值isSelected:item.getSelectedColumns()){
如果(当选){
columnsCount++;
}
}
viewHolder.rowsCount.setText(context.getString(R.string.label_rowscounttext,(item.GetRecordScont()-item.getHeaderRow()),columnsCount));
}
最后一个复选框为selectedforimport=(复选框)convertView.findViewById(R.id.import\u table\u list\u toggle\u按钮);
RelativeLayout checkboxLayout=(RelativeLayout)convertView.findViewById(R.id.import\u table\u list\u toggle\u layout);
checkboxLayout.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
isSelectedForImport.performClick();
}
});
最终文本视图选择消息=(文本视图)convertView.findViewById(R.id.row\u info\u text);
isSelectedForImport.setChecked(item.isSelected());
如果(!isSelectedForImport.isChecked()){
convertView.setClickable(真);
viewHolder.titleView.setTextColor(Color.parseColor(“#8A000000”);
}否则{
convertView.setClickable(false);viewHolder.titleView.setTextColor(Color.parseColor(“#DE000000”);
}
isSelectedForImport.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
如果(((导入性)上下文).getNewApplication().hasChildren(item.getSheetId(),item.getTableId())&&!isSelectedForImport.isChecked()){
isSelectedForImport.setChecked(true);
AlertDialog.Builder=新建AlertDialog.Builder(上下文);
最终警报对话框;
setMessage(context.getString(R.string.importapplication\u appscreen\u label\u lookupwarningmessage));
setPositiveButton(context.getString(R.string.ui\u label\u continue),新的DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
对于(int i=0;i
这种情况并非总是发生,小列表也不会发生。我没有在这里的其他帖子中描述的其他常见问题(只要这个小故障没有发生,所有视图都正常工作,并且顺序正确)

XML布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/sheet_row_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:descendantFocusability="blocksDescendants"
android:orientation="horizontal">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:orientation="vertical"
    android:paddingLeft="16dp">

    <TextView
        android:id="@+id/sheet_name_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="4dp"
        android:textColor="#DE000000"
        android:textSize="16sp"
        tools:text="Sheet Name" />

    <TextView
        android:id="@+id/rows_count_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#8A000000"
        android:textSize="14sp"
        tools:text="Rows : 3" />
    <TextView
        android:id="@+id/row_info_text"
        android:textSize="12sp"
        android:layout_width="match_parent"
        android:ellipsize="end"
        android:maxLines="1"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:visibility="gone"
        tools:visibility="gone"
        tools:text="This form is looked up by "/>

</LinearLayout>

<RelativeLayout
    android:id="@+id/import_table_list_toggle_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="19dp"
    android:paddingRight="19dp"
    android:layout_alignParentRight="true">
    <CheckBox
        android:id="@+id/import_table_list_toggle_button"
        android:layout_width="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:paddingBottom="24dp"
        android:paddingTop="24dp" />
</RelativeLayout>


正如我提到的,问题是
相对布局

试试这个

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/sheet_row_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal|center_vertical"
            android:descendantFocusability="blocksDescendants"
            android:orientation="horizontal"
            android:weightSum="10">

<LinearLayout
    android:layout_width="0dp"
    android:layout_weight="8"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:orientation="vertical"
    android:paddingLeft="16dp">

    <TextView
        android:id="@+id/sheet_name_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="4dp"
        android:textColor="#DE000000"
        android:textSize="16sp"
        tools:text="Sheet Name"/>

    <TextView
        android:id="@+id/rows_count_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#8A000000"
        android:textSize="14sp"
        tools:text="Rows : 3"/>

    <TextView
        android:id="@+id/row_info_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="2dp"
        android:ellipsize="end"
        android:maxLines="1"
        android:textSize="12sp"
        android:visibility="gone"
        tools:text="This form is looked up by "
        tools:visibility="gone"/>

</LinearLayout>

<RelativeLayout
    android:id="@+id/import_table_list_toggle_layout"
    android:layout_width="0dp"
    android:layout_weight="2"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:paddingLeft="19dp"
    android:paddingRight="19dp">

    <CheckBox
        android:id="@+id/import_table_list_toggle_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:clickable="true"
        android:paddingBottom="24dp"
        android:paddingTop="24dp"/>
</RelativeLayout>


shaw listview项目的cutom布局可能是以RelativeLayout为父项的listview布局。共享您的布局。问题可能是由于您在列表项中扩大行的方式引起的。添加-使用相对布局是否错误?好的,我会解决