如何在TableLayout中更改微调器

时间:2014-03-24 07:39:38

标签: android spinner tablelayout

我创建了一个表格布局,其中包含表格行 每个表行都包含一些Linnear Layour。 Linear Layout有一个子Spinner。当我首先创建表格布局时,我正在ArrayList<TableRow> list_rows中编写每个TableRow 我为一些微调器设置了不同的值。当我使用表格布局更新活动时,我会调用重绘表格布局的功能,它可以正常工作。 我的问题是在更新活动后我想要更改某些微调器的值,并且表布局的下一次更新应该显示带有新微调器的表,但它不会发生。

 public void addColumnInRows(TableRow tableRow, boolean name, boolean has_data, int number_of_student, int number_of_column)  
    {
            // some code
            spinner = new Spinner(getContext());
            final String[] mark_5 = {"", "a", "i", "1", "2", "3", "4", "5"}; // elemets in spinner
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_item, mark_5);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
            spinner.setBackgroundColor(Color.WHITE);
            spinner.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
            spinner.setAdapter(adapter);

            spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                    parent.setSelection(position);
                }
                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                }
            });

            if (has_data == true) // draw TableLayout if i have a data
            {
                journal.Statistics(DrawTable.this, stat);
                journal.Statistics(DrawTable.this, journal.stat);
                for (int position = 0; position < mark_5.length; position++) {
                    if (number_of_column - 1 < stat.get(number_of_student).size()) {
                        if (stat.get(number_of_student).get(number_of_column-1).equals(mark_5[position])) {
                            spinner.setSelection(position);
                        }
                    }
                }
            }
     }

0 个答案:

没有答案