分配数组列表值的TextView [英] assign arraylist value to textview

查看:179
本文介绍了分配数组列表值的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的ArrayList中的值设置为TextView的

I'm trying to set the value from my arraylist to the textview

    ArrayList<Integer> arrayListPage1, arrayListPage2, arrayListPage3, arrayListPage4, arrayListPage5;

    arrayListPage1 = new ArrayList<Integer>(rangeMode);
    arrayListPage2 = new ArrayList<Integer>(rangeMode);
    arrayListPage3 = new ArrayList<Integer>(rangeMode);
    arrayListPage4 = new ArrayList<Integer>(rangeMode);
    arrayListPage5 = new ArrayList<Integer>(rangeMode);
    totalCardInPage = new int[totalPage+1];
    for(int j=1;j<=totalPage;j++){  
        int x=0;
        for(int i=1;i<=rangeMode;i++){
            if(binaryTable[i][j]==1){                   
                //maka i ada di page j
                cardInPage[j][x]=i;
                //array buat card di page 1
                if (j==1){
                    arrayListPage1.add(i);
                }else if(j==2){
                    arrayListPage2.add(i);
                }else if(j==3){
                    arrayListPage3.add(i);
                }else if(j==4){
                    arrayListPage4.add(i);
                }else if(j==5){
                    arrayListPage5.add(i);
                }
                x++;                    
            }
        }
        System.out.println("page-"+j+" jumlah kartu:"+x);
        totalCardInPage[j]=x;
    }
    System.out.println("List page 1 "+arrayListPage1);
    System.out.println("List page 2 "+arrayListPage2);
    System.out.println("List page 3 "+arrayListPage3);
    System.out.println("List page 4 "+arrayListPage4);
    System.out.println("List page 5 "+arrayListPage5);
    TextView text1 = (TextView) findViewById(R.id.text1);
    if (arrayListPage1[0]!=null){

        text1.setText(arrayListPage1[0]);
    }
    else{
        text1.setVisibility(View.GONE);
    }

    if (arrayListPage1[1]!=null){
        text1.setText(arrayListPage1[1]);
    }
    else{
        text1.setVisibility(View.GONE);
    }

但我得到了,当我试图设置数组列表值TextView的我的一个错误。说这个错误是因为我使用的ArrayList,所以我不能指定值给TextView的

but I got an error when I'm trying to set the arraylist value to my textview. The error said because I'm using arraylist so I cannot assign the value to the textview

人知道如何解决这一问题?

anyone know how to fix this?

感谢

推荐答案

这是因为你设置的整数值为你的TextView和TextView中从资源发现的字符串。转换你的整数值为String。

It happens because You set Integer value to Your TextView and TextView finds String from resources. Convert Your Integer value to String.

例如:

text1.setText(arrayListPage1.get(0).toString());

或简单的:

text1.setText(arrayListPage1.get(0) + "");

这篇关于分配数组列表值的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆