数据输入不在列标题下,我试图以直线列显示数据......但它不起作用

时间:2016-01-01 12:01:16

标签: android sqlite

你好,我是android开发的新手。我正在创建一个包含四列的应用程序。学生,年龄,人数和班级......但是列下显示的数据是无序的,我如何组织显示在正确列中的数据?

这是我的代码。 我的数据库名称= schooldatabase

String[] columns = new String[] { KEY_ROWID, KEY_STUDENT, KEY_AGE, KEY_ID_NUMBER, KEY_CLASS };
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);

String result =  "";
ArrayList<String> mArrayList = new ArrayList<String>();                

int IROW = c.getColumnIndex(KEY_ROWID);
int ISTUDENT = c.getColumnIndex(KEY_STUDENT);
int IAGE = c.getColumnIndex(KEY_AGE);
int INUMBER = c.getColumnIndex(KEY_ID_NUMBER);
int ICLASS = c.getColumnIndex(KEY_CLASS);
// ////////////////////////////////////////////////////////
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {

    // ////////////////////////////////////////////////////
    result = result + c.getString(IROW) + " " + c.getString(ISTUDENT)
        + " " + " " + c.getString(IAGE) + " " + " "
        + c.getString(INUMBER) + " " + "  " + c.getString(ICLASS)
        + "\n";
}

return result;

1 个答案:

答案 0 :(得分:0)

您可以使用public function actionIndex() { $imodel = new Grade(); if($imodel->load(Yii::$app->request->post())) { $imodel->load(Yii::$app->request->post()); $imodel->grade; $query = Nilaiharian::find(); //select nis, $grade, nama from nilaiharian $dataProvider = new ActiveDataProvider(['query' => $query,]); return $this->render('tampil', ['imodel' => $imodel, 'dataProvider' => $dataProvider,] ); } else { return $this->render('index', ['imodel' => $imodel, ] ); } } 查询项目,如下所示:

<?php 

    echo "Nilai untuk ".$imodel->grade; 
    echo "<br>";
    echo GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        'nis',
        $imodel->grade,
        'nama',
        ['class' => 'yii\grid\ActionColumn',
                    'template'  => '{view}{update}{delete}',
                    'buttons' => [
                            'view' => function ($url, $model) {
                                    return Html::a('<i class="glyphicon glyphicon-eye-open"></i>', 
                                      $url, ['title' => Yii::t('app', 'Show'), 'name'=>'view', 'value'=>'view', 'style' => 'margin-right:10px;', ]);
                            },
                            'update' => function ($url, $model) {
                                    return Html::a('<i class="glyphicon glyphicon-pencil"></i>', 
                                      $url, ['title' => Yii::t('app', 'Edit'), 'name'=>'update', 'style' => 'margin-right:10px;', ]);
                            },
                            'delete' => function ($url, $model) {
                                    return Html::a('<i class="glyphicon glyphicon-trash"></i>', 
                                      $url, ['title' => Yii::t('app', 'Delete'), 'name'=>'delete', 'data-confirm'=>'Are you sure you want to delete this record?']);
                            }
                    ]
            ],
     ], 

     ]); 
?>

我认为数据是否有序取决于您如何解决这些数据,当您获得所有数据时,您可以根据需要处理这些数据。