I have got a xml file with listview in a file list.xml
<LinearLayout>
<Button
android:id="@+id/countryfilter"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Load Country data"/>
<Button
android:id="@+id/domain_filter"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Load Domain data"/>
<ListView
android:id="@+id/listContents"
android:layout_width="wrap_content"
android:visibility="gone"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Following is the code that I have within row.xml
<CheckedTextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Some text here"
android:textSize="18sp"
android:gravity="center_vertical"
android:clickable="true"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:focusable="true"
android:checked="false"
android:onClick="toggle"/>
During run time, the listview will be made made visible and its data will be set.
Here Im setting onClickListener for load country list button. Countrylist item has got list of some countries
countryListBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lv.setVisibility(View.VISIBLE);
initCountryList();
customAdapter = new CustomAdapter(
getApplicationContext(), R.layout.filters, android.R.id.text1, countryList
);
lv.setAdapter(customAdapter);
}
});
Here Im setting onClickListener for load domain list button. domainList contains list of domains
domainListBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
lv.setVisibility(View.VISIBLE);
initDomainList();
domainAdapter = new CustomAdapter(getApplicationContext(), R.layout.filters, android.R.id.text1, domainList
);
lv.setAdapter(domainAdapter);
}
});
The problem is that,
listview is populated with values each time when buttons are clicked. so the listview has got same values that are being displayed multiple times.