选择微调器项目编程自定义适配器

时间:2016-10-22 11:10:39

标签: android

我有一个使用以下代码填充的微调器:

String[] routeList = response.split("\\^");
List<PresetDetails> list = new ArrayList<PresetDetails>();
for (String x : routeList) {
    list.add(new PresetDetails(Arrays.asList(x.split(",")).get(0), Arrays.asList(x.split(",")).get(1), Arrays.asList(x.split(",")).get(2), Arrays.asList(x.split(",")).get(3)));
}
ArrayAdapter<PresetDetails> adap = new ArrayAdapter<PresetDetails>(activity, android.R.layout.simple_spinner_item, list);
TrackingLocations_Spinner_Presets.setAdapter(adap);

PresetDetails

public class PresetDetails {
    public String PresetID;
    public String Latitude;
    public String Longitude;
    public String PresetName;




    public PresetDetails( String PresetID, String  Latitude, String Longitude,String PresetName  ) {
        this.PresetID = PresetID;
        this.Latitude = Latitude;
        this.Longitude = Longitude;
        this.PresetName = PresetName;
    }

    @Override
    public String toString() {
        return PresetName;
    }

在另一段代码中,我有PresetID并且必须以编程方式选择填充的微调器中的相应项。我怎样才能做到这一点。

1 个答案:

答案 0 :(得分:0)

for(int i = 0; i < list.size(); i++) {
    if(list.get(i).equals("your id")) {
        spinnerObject.setSelection(i);
        break;
    }
}