Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android数组结果显示在多个文本视图中_Android_Arrays_Textview - Fatal编程技术网

Android数组结果显示在多个文本视图中

Android数组结果显示在多个文本视图中,android,arrays,textview,Android,Arrays,Textview,我试图将我从数组函数得到的结果显示到textview中,数组函数有多个结果 例如,如果结果为1、3、5、7、9,则每个结果将显示在每个文本视图中。将有10个文本视图,在这种情况下仅使用5个文本视图 有人知道怎么做吗 //this function is used to determine how many page can be flipped. I used viewFlipper in this case. rangeValue is depending on the user input

我试图将我从数组函数得到的结果显示到textview中,数组函数有多个结果

例如,如果结果为1、3、5、7、9,则每个结果将显示在每个文本视图中。将有10个文本视图,在这种情况下仅使用5个文本视图

有人知道怎么做吗

 //this function is used to determine how many page can be flipped. I used viewFlipper in this case. rangeValue is depending on the user input
 public int binaryRangePage(int rangeValue){
    int flipperPage = 1;
    while(rangeValue >= 2){
        rangeValue = rangeValue/2;
        flipperPage++;
    }
    return flipperPage;
}


    totalPage = binaryRangePage(rangeMode);
            //initialization range for 2 dimensional table
    binaryTable = new int[rangeMode+1][totalPage+1];
    int n;
    int i;
    int k;          
    //looping the range
    for(i=1; i<=rangeMode; i++){
        n = i;
        flipperPage = 1;
        //looping for each page in viewFlipper
        while(n>0){
            remainder = n%2;
            binaryTable[i][flipperPage] = remainder;
            n = (int) Math.floor(n/2);
            System.out.println("remainder["+i+"]["+flipperPage+"]: "+remainder);            
            flipperPage++;

            }
        //if the current page is less than total page which should has value, the remainder page will be filled with 0
        if(flipperPage<=totalPage){
            //looping untuk remainder page dgn 0
            for(k=flipperPage; k<=totalPage;k++){
                binaryTable[i][flipperPage] = 0;
                System.out.println("remainder["+i+"]["+flipperPage+"]: 0");
                flipperPage++;
            }
        }
//此函数用于确定可以翻转多少页。我在本例中使用了viewFlipper。范围值取决于用户输入
公共int-binaryRangePage(int-rangeValue){
int fliperpage=1;
而(范围值>=2){
rangeValue=rangeValue/2;
flipperPage++;
}
返回网页;
}
totalPage=binaryRangePage(rangeMode);
//二维表格的初始化范围
binaryTable=new int[rangeMode+1][totalPage+1];
int n;
int i;
int k;
//循环范围
对于(i=1;i0){
余数=n%2;
二进制表[i][flipperPage]=余数;
n=(int)数学层(n/2);
System.out.println(“余数[“+i+”][“+flipperPage+”]:“+rements”);
flipperPage++;
}
//如果当前页面小于应有值的总页面,则剩余页面将填充0
if(fliperpagexml中的示例代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" 
    android:orientation="vertical">

    <TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />
    <TextView
        android:id="@+id/textview1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />
    <TextView
        android:id="@+id/textview2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

</LinearLayout>

这只是更改数组和文本视图的示例。

您需要动态创建文本视图。这是最佳方法

LinearLayout layout  = (LinearLayout) findViewById(R.id.linearLayout1);

for (int i = 0; i <= array.length ; i++){
      TextView tv = new TextView(getApplicationContext());
      tv.setText(array[i]);
      layout.addView(tv);
}

如果可能的话,结果将随机显示在textview中,你到目前为止尝试了什么?从code创建
textview
,检查这个链接@NambiNarayanan我已经尝试获取这些数组列表。现在我想在我的textview中显示这些列表。textview是固定的。因此在我的页面中,将有10个textview。如果有4个列表,只有4个t将使用extview,并且remaind textview将为空。@Mobi我的textview在我的页面中是固定的,只有那些数组列表依赖于用户输入。如果我的textview是固定的,就像有10个textview一样,这是可能的吗?
LinearLayout layout  = (LinearLayout) findViewById(R.id.linearLayout1);

for (int i = 0; i <= array.length ; i++){
      TextView tv = new TextView(getApplicationContext());
      tv.setText(array[i]);
      layout.addView(tv);
}
if (array[0]!=null){
    textView1.setText(array[0]);
}
else{
    textView1.setVisibility(View.GONE);
}

if (array[1]!=null){
    textView2.setText(array[1]);
}
else{
    textView2.setVisibility(View.GONE);
}
.
.
.
if (array[9]!=null){
    textView10.setText(array[9]);
}
else{
    textView10.setVisibility(View.GONE);
}