我已經開發了一個自定義listview應用程序,它工作正常,但滾動佈局的數據更改。android動態列表視圖滾動
我的列表視圖佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/layout_start_lesson"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textlesson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:padding="8dp"
android:text="Medium Text"
android:textSize="18dp"
android:textStyle="bold" />
<View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#E0E0E0" />
</LinearLayout>
<!-- Layout Progress -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textViewProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical|center_horizontal"
android:padding="5dp"
android:text="@string/progress"
android:textSize="16dp" />
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical|center_horizontal"
android:layout_weight="0.5"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/progressbar_style" />
<TextView
android:id="@+id/textProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:text="Medium Text"
android:textSize="16dp" />
</LinearLayout>
<!-- Layout Test Liv 1-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textViewTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical|center_horizontal"
android:padding="5dp"
android:text="@string/testLiv1"
android:textSize="16dp" />
<ProgressBar
android:id="@+id/progressBarTest"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical|center_horizontal"
android:layout_weight="0.5"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/progressbar_style" />
<TextView
android:id="@+id/textPercentTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:text="Medium Text"
android:textSize="16dp" />
</LinearLayout>
<!-- Layout Test Liv 2-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textViewTestLiv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical|center_horizontal"
android:padding="5dp"
android:text="@string/testLiv2"
android:textSize="16dp" />
<ProgressBar
android:id="@+id/progressBarTestLiv2"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical|center_horizontal"
android:layout_weight="0.5"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/progressbar_style" />
<TextView
android:id="@+id/textPercentTestLiv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:text="Medium Text"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
這裏我聲明:
StartLessonAdapter adapter = new StartLessonAdapter(datalist);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() { .... }
我startlessonadapter類:
public View getView(int position, View view, ViewGroup parent) {
final StartLessonTestBean entry = (StartLessonTestBean) languageBean
.get(position);
int main = R.layout.layout_start_lesson;
final ViewHolderLanguage holder;
View convertView = null;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(main, null);
} else {
convertView = view;
}
holder = new ViewHolder();
holder.txtLesson = (TextView) convertView.findViewById(R.id.textlesson);
holder.txtLesson.setText(entry.getLesson().trim());
// ---- START Progress -------
holder.progressBarTraining = (ProgressBar) convertView
.findViewById(R.id.progressBar);
holder.progressBarTraining.setMax(100);
holder.progressBarTraining.setProgress(entry.getProgressTraining());
holder.textProgressTraining = (TextView) convertView
.findViewById(R.id.textProgress);
String pr = entry.getTxtProgressTraining().trim();
holder.textProgressTraining.setText(pr);
// ----- END Progress
// ---- START Test Liv 1 -------
holder.progressTestLiv1Bar = (ProgressBar) convertView
.findViewById(R.id.progressBarTest);
holder.progressTestLiv1Bar.setMax(100);
holder.progressTestLiv1Bar.setProgressDrawable(convertView
.getResources().getDrawable(R.drawable.progressbartest_style));
holder.progressTestLiv1Bar.setProgress(entry.getProgressTestLiv1Ok());
holder.progressTestLiv1Bar.setSecondaryProgress(entry
.getProgressTestLiv1NotOk());
holder.textTestLiv1Progress = (TextView) convertView
.findViewById(R.id.textPercentTest);
pr = entry.getTxtProgressTestLiv1().trim();
holder.textTestLiv1Progress.setText(pr);
// ----- END Test Liv 1
// ---- START Test Liv 2 -------
holder.progressTestLiv2Bar = (ProgressBar) convertView
.findViewById(R.id.progressBarTestLiv2);
holder.progressTestLiv2Bar.setMax(100);
holder.progressTestLiv2Bar.setProgressDrawable(convertView
.getResources().getDrawable(R.drawable.progressbartest_style));
holder.progressTestLiv2Bar.setProgress(entry.getProgressTestLiv2Ok());
holder.progressTestLiv2Bar.setSecondaryProgress(entry
.getProgressTestLiv2NotOk());
holder.textTestLiv2Progress = (TextView) convertView
.findViewById(R.id.textPercentTestLiv2);
pr = entry.getTxtProgressTestLiv2().trim();
holder.textTestLiv2Progress.setText(pr);
// ----- END Test Liv 2
holder.position = position;
return convertView;
}
public int getCount() {
return languageBean.size();
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
return position;
}
爲什麼數據已滾動後改變? 在佈局我有3 TextView的和3個進度條,
滾動後,我只有3 TextView的和1個進度
您能告訴我們您的StartLessonAdapter的代碼嗎? –
用StartLessonAdapter類改變了主要風格 – shuttle1978
基本上當你滾動列表視圖適配器刷新和爲什麼它會這樣做!我很早就面臨這個問題 – UnderGround