我的代码遇到了问题。
我从ArrayList填充Listview,然后由文件数据填充。
问题是当我向下滚动或向上滚动时,我得到重复的项目。我该如何解决?
这是我的代码:
public class ListChannels extends ListActivity {
ArrayList<String> channelname = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_channels);
listchannels();
channelname = new ArrayList<String>(new LinkedHashSet<String>(channelname));
this.setListAdapter(new ArrayAdapter<String>(
this, R.layout.mylistchannel,
R.id.Channelname,channelname));
}
我从File
填充ArrayList的代码 InputStreamReader inputreader = new InputStreamReader(testFile.getReadStream());
BufferedReader buffreader = new BufferedReader(inputreader);
String key,value = null;
do {
key = buffreader.readLine();
if(key != null)
value = buffreader.readLine();
channelname.add(key);
} while (key != null && value != null);
感谢您的帮助。提前谢谢!