Android ScrollView末尾的TableLayout异常行为

Android ScrollView末尾的TableLayout异常行为,android,scrollview,tablelayout,Android,Scrollview,Tablelayout,我正在以编程方式在滚动视图中创建一些TableLayouts,我可以通过动态添加/删除一些TableRows来更改这些TableLayout的内容 问题是,除了最后一个没有明显原因的奇怪行为外,其他一切都正常 当我在“问题”表格上方的TableLayouts中添加/删除一些TableRows时,表格中的一些单元格突然以每列一个字符的形式显示列中的内容,并在不拉伸单元格的情况下离开单元格,这使得内容无法读取 我不知道为什么会这样,因为这是唯一一个有这个问题的。 我认为问题可能与以下事实有关:Scr

我正在以编程方式在
滚动视图中创建一些
TableLayouts
,我可以通过动态添加/删除一些
TableRows
来更改这些
TableLayout
的内容

问题是,除了最后一个没有明显原因的奇怪行为外,其他一切都正常

当我在“问题”表格上方的
TableLayouts
中添加/删除一些
TableRows
时,表格中的一些单元格突然以每列一个字符的形式显示列中的内容,并在不拉伸单元格的情况下离开单元格,这使得内容无法读取

我不知道为什么会这样,因为这是唯一一个有这个问题的。 我认为问题可能与以下事实有关:
ScrollView
中的内容发生变化时正在调整自身的大小,并且由于“有问题的”
TableLayout
位于
ScrollView
的末尾,它导致了一些意外的变化

我该如何解决这个问题

代码:

private List addModifiableLinesToView(最终表格布局视图、最终字符串视图、,
最终整型[]ordreVoulu,最终树状图,最终放射组rg){
最终列表listRes=新的ArrayList();
试一试{
//问题示例:CSV_bt.CSV
InputStream is=新文件InputStream(Environment.getExternalStorageDirectory()+
“/”+文件夹\u main+“/”+导入的\u数据+“/”+fichier);
CSVFile csv=新的CSVFile(is);
List tableau=csv.findLines(indicateposte.getText().toString());
圣殿骑士名单;
//为您的家人和家人送去节日的晚餐
for(字符串[]s:tableau){
templast=newarraylist();
//我遇见了一位来自世界各地的朋友
字符串[]VAL=FilterRevaleurs(s,ordreVoulu);
final TableRow row=新的TableRow(getApplicationContext());
row.setLayoutParams(新的TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_父级,
TableLayout.LayoutParams.WRAP_CONTENT);
int n=0;
//这是一个统一的画面
用于(字符串值:VAL){
视图分隔符=新视图(getApplicationContext());
divider.setLayoutParams(新的TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_父级,TableLayout.LayoutParams.MATCH_父级);
分隔线。背景颜色(颜色。黑色);
final ViewSwitcher ViewSwitcher=新的ViewSwitcher(getApplicationContext());
TextView t=新的TextView(MainActivity.this);
LinearLayout.LayoutParams参数1=新的LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_内容,
ViewGroup.LayoutParams.WRAP_内容);
t、 setLayoutParams(参数1);
t、 setMaxWidth(0);
如果(fichier.equals(“csv_amm.csv”)&&n==3)
{
valeur=valeur.trim();
int val=!valeur.equals(“”)Integer.parseInt(valeur):0;
AMMValue ammval=新的AMMValue(val);
t、 setText(ammval.getLibelle());
}
其他的
t、 塞特克斯(瓦勒尔);
t、 设置重力(重心);
t、 setTextColor(颜色为黑色);
t、 大小(14);
t、 设置填充(5,5,5,5);
t、 setOnClickListener(新视图。OnClickListener(){
@凌驾
公共void onClick(视图){
如果(rg.getCheckedRadioButtonId()!=-1)
viewSwitcher.showNext();
}
});
viewSwitcher.addView(t,
新建TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_父项,
TableRow.LayoutParams.MATCH_PARENT,1f));
最终字符串键=(字符串)map.keySet().toArray()[n];
if(key.contains(“编辑文本”))
{
最终编辑文本e=新编辑文本(MainActivity.this);
LinearLayout.LayoutParams参数2=新的LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_内容,
ViewGroup.LayoutParams.WRAP_内容);
e、 setLayoutParams(params2);
e、 设置单线();
e、 setImeOptions(EditorInfo.IME\u ACTION\u DONE);
e、 setBackgroundColor(getResources().getColor(R.color.orange));
e、 setMaxWidth(0);
e、 大小(14);
e、 设置填充(5,5,5,5);
e、 设置重力(重心);
//你的键盘上的数字是多少
if(键包含(“编号”))
e、 设置输入类型(输入类型.类型\类别\编号);
else if(key.contains(“Text”))
e、 设置输入类型(输入类型.类型\类别\文本);
/*
*TextChangedListener qui permet de retourner au模式“TextView”
*量化宽松对超级信贷的吹捧
*/
e、 addTextChangedListener(新的TextWatcher(){
@凌驾
更改前的公共无效(CharSequence CharSequence,int i,int i1,int i2){
}
@凌驾
public void onTextChanged(CharSequence CharSequence,i
private List<List<View>> addModifiableLinesToView(final TableLayout view, final String fichier,
                                                  final int[] ordreVoulu, final TreeMap<String,ArrayList> map, final RadioGroup rg) {
    final List<List<View>> listRes = new ArrayList<>();

    try{
        //Recherche de valeurs dans le fichier CSV du module en question ex: csv_bt.csv
        InputStream is = new FileInputStream(Environment.getExternalStorageDirectory() +
                "/" + folder_main + "/" + imported_data + "/" + fichier);
        CSVFile csv = new CSVFile(is);
        List<String[]> tableau = csv.findLines(indicePoste.getText().toString());
        List<View> tempList;

        //Pour chaque ligne avec le bon numéro de poste trouvé dans le csv
        for (String[] s : tableau) {
            tempList = new ArrayList<>();
            //met les valeurs dans le bon ordre pour les ajouter au tableau
            String[] vals = filtreValeurs(s, ordreVoulu);
            final TableRow row = new TableRow(getApplicationContext());
            row.setLayoutParams(new TableLayout.LayoutParams(
                    TableLayout.LayoutParams.MATCH_PARENT,
                    TableLayout.LayoutParams.WRAP_CONTENT));

            int n = 0;
            //ajoute les valeurs récupérées a une ligne du tableau
            for (String valeur : vals) {

                View divider = new View(getApplicationContext());
                divider.setLayoutParams(new TableLayout.LayoutParams(
                        TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
                divider.setBackgroundColor(Color.BLACK);

                final ViewSwitcher viewSwitcher = new ViewSwitcher(getApplicationContext());

                TextView t = new TextView(MainActivity.this);
                LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);
                t.setLayoutParams(params1);
                t.setMaxWidth(0);
                if(fichier.equals("csv_amm.csv") && n == 3)
                {
                    valeur = valeur.trim();
                    int val = !valeur.equals("")?Integer.parseInt(valeur) : 0;
                    AMMValue ammval = new AMMValue(val);
                    t.setText(ammval.getLibelle());
                }
                else
                    t.setText(valeur);

                t.setGravity(Gravity.CENTER);
                t.setTextColor(Color.BLACK);
                t.setTextSize(14);
                t.setPadding(5,5,5,5);
                t.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if(rg.getCheckedRadioButtonId() != -1)
                            viewSwitcher.showNext();
                    }
                });

                viewSwitcher.addView(t,
                        new TableRow.LayoutParams(
                                TableRow.LayoutParams.MATCH_PARENT,
                                TableRow.LayoutParams.MATCH_PARENT, 1f));

                final String key = (String)map.keySet().toArray()[n];

                if(key.contains("EditText"))
                {
                    final EditText e = new EditText(MainActivity.this);
                    LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(
                            ViewGroup.LayoutParams.WRAP_CONTENT,
                            ViewGroup.LayoutParams.WRAP_CONTENT);
                    e.setLayoutParams(params2);
                    e.setSingleLine();
                    e.setImeOptions(EditorInfo.IME_ACTION_DONE);
                    e.setBackgroundColor(getResources().getColor(R.color.orange));
                    e.setMaxWidth(0);
                    e.setTextSize(14);
                    e.setPadding(5,5,5,5);
                    e.setGravity(Gravity.CENTER);
                    //En fonction de la valeur va afficher un clavier numérique ou non
                    if(key.contains("Number"))
                        e.setInputType(InputType.TYPE_CLASS_NUMBER);
                    else if(key.contains("Text"))
                        e.setInputType(InputType.TYPE_CLASS_TEXT);
                    /*
                     *TextChangedListener qui permet de retourner au mode "TextView"
                     *quand on supprime tout ce qui à été écris
                     */
                    e.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                        }
                        @Override
                        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                            if(e.length() == 0)
                            {
                                viewSwitcher.showPrevious();
                                cacherClavierVirtuel();
                            }
                        }

                        @Override
                        public void afterTextChanged(Editable editable) {

                        }
                    });

                    viewSwitcher.addView(e,
                            new TableRow.LayoutParams(
                                    TableRow.LayoutParams.MATCH_PARENT,
                                    TableRow.LayoutParams.MATCH_PARENT, 1f));
                }
                else if (key.contains("Spinner"))
                {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            final Spinner spin = new Spinner(getApplicationContext());
                            spin.getBackground().setColorFilter(
                                    getResources().getColor(R.color.noir),
                                    PorterDuff.Mode.SRC_ATOP);
                            spin.setBackgroundColor(getResources().getColor(R.color.orange));
                            spin.setGravity(Gravity.CENTER);
                            spin.setPopupBackgroundResource(R.color.blanc);
                            spin.setPadding(5,5,5,5);
                            ArrayList<String> list = map.get(key);
                            final ArrayAdapter<String> adapter = new ArrayAdapter<>(
                                    MainActivity.this,
                                    R.layout.spinner_adapter,
                                    list);
                            adapter.setDropDownViewResource(
                                    android.R.layout.simple_spinner_dropdown_item);
                            spin.setAdapter(adapter);

                            //Set de la selection à 1 pour ne pas annuler tout de suite
                            spin.setSelection(1);
                            /* ItemListener qui va retourner le ViewSwitcher en mode
                             * affichage si l'on selectionne la valeur index 0 qui
                             * correspond à "Annuler" */
                            spin.setOnItemSelectedListener(
                                    new AdapterView.OnItemSelectedListener() {
                                        @Override
                                        public void onItemSelected(
                                                AdapterView<?> adapterView, View view, int i, long l) {
                                            ((TextView) adapterView.getChildAt(0)).setTextSize(14);
                                            if (adapterView.getSelectedItemPosition() == 0 && rg.getCheckedRadioButtonId() != -1) {
                                                spin.setSelection(1);
                                                viewSwitcher.showPrevious();
                                            }

                                        }

                                        @Override
                                        public void onNothingSelected(AdapterView<?> adapterView) {

                                        }
                                    });

                            viewSwitcher.addView(spin,
                                    new TableRow.LayoutParams(
                                            TableRow.LayoutParams.MATCH_PARENT,
                                            TableRow.LayoutParams.MATCH_PARENT, 1f));
                        }
                    });
                }


                tempList.add(viewSwitcher);

                row.addView(divider,
                        new TableRow.LayoutParams(
                                TableRow.LayoutParams.MATCH_PARENT,
                                TableRow.LayoutParams.MATCH_PARENT));
                row.addView(viewSwitcher,
                        new TableRow.LayoutParams(
                                TableRow.LayoutParams.MATCH_PARENT,
                                TableRow.LayoutParams.MATCH_PARENT, 1f));
                n++;
            }

            //separateur en fin de ligne
            View divider = new View(getApplicationContext());
            divider.setLayoutParams(new TableLayout.LayoutParams(
                    TableLayout.LayoutParams.MATCH_PARENT,
                    TableLayout.LayoutParams.MATCH_PARENT));
            divider.setBackgroundColor(Color.BLACK);
            row.addView(divider,
                    new TableRow.LayoutParams(
                            TableRow.LayoutParams.MATCH_PARENT,
                            TableRow.LayoutParams.MATCH_PARENT));
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    view.addView(row);
                }
            });

            //separateur horizontal
            final View dividerH = new View(getApplicationContext());
            dividerH.setLayoutParams(new TableLayout.LayoutParams(
                    TableLayout.LayoutParams.MATCH_PARENT,
                    3));
            dividerH.setBackgroundColor(Color.BLACK);
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    view.addView(dividerH, new TableLayout.LayoutParams(
                            TableLayout.LayoutParams.MATCH_PARENT,
                            3));
                }
            });
            listRes.add(tempList);
        }
    }
    catch (ArrayIndexOutOfBoundsException e)
    {
        e.printStackTrace();
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(MainActivity.this,
                        "Erreur de format du CSV pour : " + view.getTag().toString(),
                        Toast.LENGTH_LONG).show();
            }
        });

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    return listRes;