Java Android-listview有时在转换视图之前不会显示嵌套的文本视图

Java Android-listview有时在转换视图之前不会显示嵌套的文本视图,java,android,listview,textview,Java,Android,Listview,Textview,我正在开发一个应用程序,它解析外部文件中的数据,然后使用自定义适配器创建一个listview。适配器将xml布局中的各行放大。该行由两部分组成-按钮部分(每行相同)和文本部分(从源arraylist中解析的数据动态生成) 我遇到的问题是,有些行在第一次渲染时无法正确渲染。以下是指向所需结果图像的链接: 注意按钮之间的数字-表示源arraylist中元素的顺序。但是,当第一次将适配器设置为listview时,我得到以下结果: 其中有几行呈现为see-fat块,没有显示我在适配器中添加到它们的文

我正在开发一个应用程序,它解析外部文件中的数据,然后使用自定义适配器创建一个listview。适配器将xml布局中的各行放大。该行由两部分组成-按钮部分(每行相同)和文本部分(从源arraylist中解析的数据动态生成)

我遇到的问题是,有些行在第一次渲染时无法正确渲染。以下是指向所需结果图像的链接:

注意按钮之间的数字-表示源arraylist中元素的顺序。但是,当第一次将适配器设置为listview时,我得到以下结果:

其中有几行呈现为see-fat块,没有显示我在适配器中添加到它们的文本视图。然而,文本视图就在那里——我试着给它们分配id,然后通过id成功地找到它们并返回它们的文本

有些行在第一次正确渲染。缺陷行的顺序在渲染之间保持不变,但在解析来自不同外部文件的数据时会发生变化

在滚动使有缺陷的行在listview中不再可见并向后滚动后,有问题的行正确呈现,这就是我获得所需结果屏幕截图的方式

由于声誉限制,我不能发布超过2个链接,但在更改代码让应用程序完成所有工作,然后将textview的文本设置为文本,而不管它解析了什么之后,我遇到了一个类似的问题。缺陷行的顺序和数量已更改

无论我从哪个文件解析,listview的前两行似乎总是有缺陷的

如果有什么帮助的话,我会在一台配有4.4.2 android的联想X2-EU上运行这个程序

提前感谢您对我的任何帮助

这是我的自定义适配器:

public class AdapterCardList extends ArrayAdapter {

private String TAG = "AdapterCardList";
private Context theContext;
private ArrayList<Card> theCards; //the source arraylist
public Hammer theHammer; //holds some data
public int number;

public AdapterCardList(Context context, int rowLayout, ArrayList<Card> cards, Hammer hammer) {
    super(context, rowLayout, cards);
    theCards = cards;
    theContext = context;
    theHammer = hammer;
    number = 0;
}

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

    View rowView;

    if ((convertView==null)){
        LayoutInflater inflater = (LayoutInflater) theContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rowView = inflater.inflate(R.layout.row_of_card_list, parent, false);
    }
    else{
        rowView = convertView;
    }



    LinearLayout rowLayout = (LinearLayout) rowView.findViewById(R.id.rowHorizontalTextLayout);
    rowLayout.removeAllViews();



    TextView quantText = (TextView) rowView.findViewById(R.id.textViewQuantity);
    quantText.setText(String.valueOf(position));


    int allCollLength = rowView.findViewById(R.id.rowHorizontalLayout).getWidth()-rowView.findViewById(R.id.rowHorizontalButtonsLayout).getWidth();
    int oneCollLength = (int)(((float)allCollLength)/(theHammer.elementsToPrint.length+1));

    Boolean toBePrinted = false;
    for (int i = 0; i < theCards.get(position).returnTypesLength(); i++) {

        //I parse more info than I show in listview. Here I decide if I show.
            if (theHammer.elementsToPrint[x].equals(theCards.get(position).returnType(i))) {
                toBePrinted = true;
                x = theHammer.elementsToPrint.length;
            }
            else if (theHammer.primaryIdentifier.equals(theCards.get(position).returnType(i))) {
                toBePrinted = true;
                x = theHammer.elementsToPrint.length;

            }
            else {
                toBePrinted=false;}


        }

        if (toBePrinted) {


            Log.d(TAG, "Authorised to print the value of type " + theCards.get(position).returnType(i));
            TextView newText = new TextView(theContext);



            newText.setLayoutParams(new LinearLayout.LayoutParams(oneCollLength, LinearLayout.LayoutParams.WRAP_CONTENT));
            newText.setId(i);
            Log.d(TAG, "Set the id to " + newText.getId());

            String textToSet = theCards.get(position).returnValue(i);
            newText.setText(textToSet);
            rowLayout.addView(newText);
            Log.d(TAG, "Added the value :" + theCards.get(position).returnValue(i));

        }

    }


    return rowView;

}

}
这是我一行的布局

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"

android:id="@+id/rowHorizontalLayout" >



<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:background="@color/green"
    android:layout_centerVertical="true"
    android:id="@+id/rowHorizontalButtonsLayout">



    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:text="-"
        android:id="@+id/button2" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="0"
        android:id="@+id/textViewQuantity"
        />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:text="+"
        android:id="@+id/button3"/>

</LinearLayout>


<LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/red"
    android:layout_alignParentLeft="true"
    android:id="@+id/rowHorizontalTextLayout"
    android:layout_toStartOf="@id/rowHorizontalButtonsLayout"
    android:layout_alignParentStart="false">


</LinearLayout>