Java – calling notifydatasetchanged from inside the adapter failed
I have an adapter (extended baseadapter). I tried to call notifydatasetchanged(), but it didn't work. I believe notifydatasetchanged() is actually called, based on entering it using the eclipse debugger. However, it won't call getview(). The data under my adapter is changing, as it should be. I have a method updatesettings() in the adapter, It is used to update the data at the bottom of the adapter. If I call updateSettings () from ListViewActivity, I have no problem. NotifyDataSetChanged () is the same as I expected. But when I call updateSettings () from the adapter, notifyDataSetChanged () does not work. Do I try to call notifyDataSetChanged () from the adapter to do something fundamentally wrong? Here are some of my codes:
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;
}
In this block, I set the row view and attached the event handler to the seekbar. What I want to happen is that when someone scrolls the seekbar, it will update the text above it. This is my updatesettings() method:
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()" );
}
Any opinion is appreciated!
thank you.
resolvent:
Just add
**Within your adapter, the application will reload your list
^^