我有一个适配器(扩展BaseAdapter),我试图调用notifyDataSetChanged(),但它不起作用.我相信notifyDataSetChanged()实际上是被调用的,基于使用Eclipse调试器进入它.但是,它不会调用getVIEw().我的适配器下面的数据正在改变,正如它应该的那样.我在适配器中有一个方法updateSettings(),用于更新适配器底层的数据.如果我从ListVIEwActivity调用updateSettings(),我没有任何问题… notifyDataSetChanged()的行为与我期望的一样.但是当我从适配器中调用updateSettings()时,notifyDataSetChanged()不起作用.我是否尝试从适配器中调用notifyDataSetChanged()来做一些根本错误的事情?这是我的一些代码:
public VIEw getVIEw( int position, VIEw convertVIEw, VIEwGroup parent ){ Log.d( CLASS_name, "Entered getVIEw()" ); VIEw row = convertVIEw; _settingVIEwHolder = new PhonesettingVIEwHolder(); final int index = position; /* If this is the first time the List is being built, get all of the UI Widgets * and store them in a PhonesettingVIEwHolder object for future use on * subsequent writing of the List. */ if( row == null ) { LayoutInflater inflater = (LayoutInflater)_context.getSystemService( Context.LAYOUT_INFLATER_SERVICE ); row = inflater.inflate( R.layout.phone_List_complex, null, false ); _settingVIEwHolder.txtSettingname = (TextVIEw)row.findVIEwByID( R.ID.phone_List_complex_Title ); _settingVIEwHolder.txtSettingValue = (TextVIEw)row.findVIEwByID( R.ID.phone_List_complex_caption ); _settingVIEwHolder.sbTimeout = (Seekbar)row.findVIEwByID( R.ID.slIDer ); _settingVIEwHolder.txtPercent = (TextVIEw)row.findVIEwByID( R.ID.percent ); _settingVIEwHolder.sbTimeout.setMax( 30 ); _settingVIEwHolder.sbTimeout.setProgress( 1 ); // associate this PhonesettingVIEwHolder object with the row row.setTag( _settingVIEwHolder ); } else { // get the PhonesettingVIEwHolder object that is associated with this row _settingVIEwHolder = (PhonesettingVIEwHolder)row.getTag(); } // get Setting object and store values in PhonesettingVIEwHolder object final Setting setting = _settings.get( position ); _settingVIEwHolder.txtSettingname.setText( setting.getSettingname() ); Log.d( CLASS_name, "setting.getSettingValue() = " + setting.getSettingValue() ); _settingVIEwHolder.txtSettingValue.setText( setting.getSettingValue() ); /* Event handlers for Seekbar */ _settingVIEwHolder.sbTimeout.setonSeekbarchangelistener( new OnSeekbarchangelistener() { public voID onProgressChanged( Seekbar seekbar, int progress, boolean isUser ) { Log.d( CLASS_name, "Entered onProgressChanged()" ); String percent = String.valueOf( progress ); updateSettings( index, percent ); } public voID onStartTrackingtouch( Seekbar seekbar ) { // nothing to do here } public voID onStopTrackingtouch( Seekbar seekbar ) { // nothing to do here } }); return row;}
在这个块中,我设置了行视图并将事件处理程序附加到Seekbar.我想要发生的是当有人滚动Seekbar时,它会更新它上面的文本.这是我的updateSettings()方法:
public voID updateSettings( int index, String progress ) { Log.d( CLASS_name, "Entered updateSettings()" ); Setting setting = new Setting( SETTING_name, progress ); _settings.set( index, setting ); Log.d( CLASS_name, "Calling notifyDataSetChanged()" ); notifyDataSetChanged(); Log.d( CLASS_name, "Returned from notifyDataSetChanged()" ); }
任何见解都表示赞赏!
谢谢.
解决方法:
只需添加
notifyDataSetChanged()
**在您的适配器内,应用程序将重新加载您的列表.
^^
总结以上是内存溢出为你收集整理的java – 从适配器内部调用notifyDataSetChanged失败全部内容,希望文章能够帮你解决java – 从适配器内部调用notifyDataSetChanged失败所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)