All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robobinding.widget.adapterview.SelectedItemPositionAttribute Maven / Gradle / Ivy

The newest version!
package org.robobinding.widget.adapterview;

import org.robobinding.property.ValueModel;
import org.robobinding.viewattribute.property.TwoWayPropertyViewAttribute;
import org.robobinding.widgetaddon.adapterview.AdapterViewAddOn;

import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;

/**
 * 
 * @since 1.0
 * @version $Revision: 1.0 $
 * @author Robert Taylor
 */
public class SelectedItemPositionAttribute implements TwoWayPropertyViewAttribute, AdapterViewAddOn, Integer> {

	@Override
	public void updateView(AdapterView view, Integer newPosition, AdapterViewAddOn viewAddOn) {
		view.setSelection(newPosition);
	}

	@Override
	public void observeChangesOnTheView(AdapterViewAddOn viewAddOn, final ValueModel valueModel, AdapterView view) {
		viewAddOn.addOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView parent, View view, int position, long id) {
				valueModel.setValue(position);
			}

			@Override
			public void onNothingSelected(AdapterView arg0) {
				valueModel.setValue(AdapterView.INVALID_POSITION);
			}
		});
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy