런타임시 ListView에 요소를 동적으로 추가하려고합니다. 여기 내 코드가있다.런타임에 ListView 행에 객체 추가
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/category_row"
android:orientation="horizontal" >
<!-- Contents will be added at Runtime -->
</LinearLayout>
내 어댑터 행의 첫 번째 부부는 뒤죽박죽에 보이는 것을 어떻게되는지 이제
@Override
public View getView(final int position, final View convertView,
final ViewGroup parent) {
View searchResultsRow = convertView;
LinearLayout linearLayout;
TextView e1,e2,e3,e4;
if (searchResultsRow == null) {
LayoutInflater layoutInflator = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
searchResultsRow = layoutInflator.inflate(
R.layout.categories_row_object, null);
linearLayout = (LinearLayout) searchResultsRow.findViewById(R.id.category_row);
}
e1 = new TextView(context);
e2 = new TextView(context);
e3 = new TextView(context);
e4 = new TextView(context);
e1 = new TextView(context);
e1.setText("Fashion");
linearLayout.addView(e1);
e2 = new TextView(context);
e2.setText("Men");
linearLayout.addView(e2);
e3 = new TextView(context);
e3.setText("Casual Wear");
linearLayout.addView(e3);
e4 = new TextView(context);
e4.setText("Jeans");
linearLayout.addView(e4);
return searchResultsRow;
}
에 의해 재정의의 getView 기능. 여러 행이 같은 행에 추가 된 것과 같습니다. 내가 도대체 뭘 잘못하고있는 겁니까 ? ConvertView! = NULL이있는 LinearLayout이 이니셜되지 않은 경우
친절 감사를
searchResultsRow가 다시 사용되므로 이전에 사용한 모든 항목이 이미 포함되어 있습니다. – njzk2
그렇다면 나는 무엇을해야합니까? – user1730789