2017-03-03 74 views
1

這是我用微調arrayadapter class.when我很這裏滾動列表視圖我的我的微調項值的變化,我使用(地圖MYMAP =新的HashMap();)我想微調器位置選定項目的文本

但我不能能夠獲得選定的微調項與列表視圖項..

public class Lv_001 extends ArrayAdapter<String> { 

    Map<Integer, Integer> myMap = new HashMap<Integer, Integer>(); 
    List<String> categories; 
    String[] name; 
    Context context; 
    TextView textView; 
    Spinner spinner; 
    String data, val; 
    String sp = null; 
    ArrayList<String> list = new ArrayList<>(); 

    public Lv_001(Context context, String[] name, List<String> categories) { 
     super(context, R.layout.lv_list, categories); 
     this.name = name; 
     this.categories = categories; 
     this.context = context; 
    } 
    public View getView(final int position, View view, ViewGroup group) { 
     LayoutInflater inflater = LayoutInflater.from(context); 
     view = inflater.inflate(R.layout.lv_list, null); 

     textView = (TextView) view.findViewById(R.id.textView); 

     data = categories.get(position); 
     textView.setText(data.toString()); 

     spinner = (Spinner) view.findViewById(R.id.spinner); 
     ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item, name); 
     spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

     spinner.setAdapter(spinnerArrayAdapter); 
     if (myMap.containsKey(position)) { 
      spinner.setSelection(myMap.get(position)); 
     } 
     spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 
      @Override 
      public void onItemSelected(AdapterView<?> parent, View view, int spinnerPosition, long id) { 

       myMap.put(position, spinnerPosition); 

      } 

      @Override 
      public void onNothingSelected(AdapterView<?> parent) { 
      } 
     }); 
     return view; 
    } 
} 
+0

在滾動視圖 –

回答

0

這裏是一個溶液

取一分的Hashmap臨時=新的Hashmap <>();

for(i=0;i<list.size();i++){ 
temp.put(i,0) 
} 

現在,當用戶改變在該指數的2的指數變化HashMap中值 例如微調已經改變

temp.put(position,spinner.getselecteditemposition()) 

,當你使用這個加載視圖集選擇你的微調臨時HashMap的

和最後一件事,只是使用notifydatasetchanged()

+0

保護您的列表視圖與兄弟不工作 – Rajasimman

相關問題