2017-03-03 12 views
1

で位置をスピナーたい(地図MYMAP =新しいHashMapの();)は、私はこれは私が使用しそうここに私のリストビューの私のスピナー項目値の変更をスクロールしていclass.when arrayadapterと私のスピナーで選択した項目のテキスト

しかし、私は

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

scrollviewにしてあなたのリストビューを保護を使用 –

答えて

0

.. ListView項目で選択スピナーアイテムを取得することはできませんすることができますここで)一つの解

は1つのハッシュマップの一時=新しいHashMapの<を>(テイクです。

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

今、ユーザがそのインデックスでスピナーを変更したときに2の指数で例えばハッシュマップ値 を変更するには、

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

、あなたはこれを使用してビューセットの選択あなたのスピナーを読み込むに変更されました一時HashMapの

と最後だけnotifydatasetchanged()

+0

仲間が動かない – Rajasimman

関連する問題