光标没有移动到第一个

时间:2018-04-16 21:32:27

标签: android sqlite cursor

此SQLite查询运行良好。我已单独检查它,但光标没有移动到第一个并且它跳过while循环

        Cursor c = dbr.rawQuery("select result._id, result.testDate, result.obtMarks, result.TotalMarks " +
                ",student.rollNo, student.name,class.name, test.testName  from result " +
                "inner join student on student._id= result.student_id " +
                "inner join class on class._id = result.class_id " +
                "inner join test on test._id= result.test_id" ,null);


        if (c.moveToFirst()) {

            do {
                id = c.getInt(0);
                testDate = c.getString(1);
                obtMarks = c.getString(2);
                totalmarks = c.getString(3);
                rollno = c.getString(4);
                studentName =c.getString(5);
                className= c.getString(6);
                testName =c.getString(7);





               //creating the row of table
                final TableRow tableRow = new TableRow(this);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    tableRow.setId(View.generateViewId());
                }

                tableRow.setLayoutParams(new TableRow.LayoutParams(
                        TableRow.LayoutParams.FILL_PARENT,
                        TableRow.LayoutParams.WRAP_CONTENT));

                //creating the id column
                final TextView idTextView = new TextView(this);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    idTextView.setId(View.generateViewId());
                }

                idTextView.setPadding(2, 0, 50, 0);
                idTextView.setText("" + id);
                idTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);
                tableRow.addView(idTextView);//adding the view in table row


                //creating the RollNo column
                TextView rollNoTextView = new TextView(this);
                rollNoTextView.setText(rollno);
                rollNoTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

                    rollNoTextView.setId(View.generateViewId());
                }
                rollNoTextView.setPadding(2, 0, 50, 0);
                tableRow.addView(rollNoTextView);//add the second view in row of table

                //creating the studentName column
                TextView StudentNameTextView = new TextView(this);
                StudentNameTextView.setText(studentName);
                StudentNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

                    StudentNameTextView.setId(View.generateViewId());
                }
                StudentNameTextView.setPadding(2, 0, 50, 0);
                tableRow.addView(StudentNameTextView);



                //creating the className column
                TextView classNameTextView = new TextView(this);
                classNameTextView.setText(className);
                classNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

                    classNameTextView.setId(View.generateViewId());
                }
                classNameTextView.setPadding(2, 0, 50, 0);
                tableRow.addView(classNameTextView);

                //creating the TestName column
                TextView TestNameTV = new TextView(this);
                TestNameTV.setText(testName);
                TestNameTV.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

                    TestNameTV.setId(View.generateViewId());
                }
                TestNameTV.setPadding(2, 0, 50, 0);
                tableRow.addView(TestNameTV);

                //creating the testDate column
                TextView TestDateTextView = new TextView(this);
                TestDateTextView.setText(testDate);
                TestDateTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

                    TestDateTextView.setId(View.generateViewId());
                }
                TestDateTextView.setPadding(2, 0, 50, 0);
                tableRow.addView(TestDateTextView);


                //creating the obtMarks column
                TextView ObtMarksTextView = new TextView(this);
                ObtMarksTextView.setText(obtMarks);
                ObtMarksTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

                    ObtMarksTextView.setId(View.generateViewId());
                }
                ObtMarksTextView.setPadding(2, 0, 50, 0);
                tableRow.addView(ObtMarksTextView);

                //creating the totalMarks column
                TextView TotalMarksTextView = new TextView(this);
                TotalMarksTextView.setText(totalmarks);
                TotalMarksTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18f);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {

                    TotalMarksTextView.setId(View.generateViewId());
                }
                TotalMarksTextView.setPadding(2, 0, 50, 0);
                tableRow.addView(TotalMarksTextView);






                //adding the row in main table
                tableLayout.addView(tableRow, new TableLayout.LayoutParams(
                        TableLayout.LayoutParams.FILL_PARENT,
                        TableLayout.LayoutParams.WRAP_CONTENT));
                tableRow.setOnLongClickListener(new View.OnLongClickListener() {
                    @SuppressLint("ResourceAsColor")
                    public boolean onLongClick(View arg0) {
                        int i = android.support.design.R.color.material_grey_300;
                        tableRow.setBackgroundColor(i);
                        Dialog1(tableRow, idTextView);
                        return true;    // <- set to true
                    }
                });


            } while (c.moveToNext());

0 个答案:

没有答案