Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.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表视图中以列的形式从数据库中获取数据,并根据页面显示将行数限制为10_Android_Android Layout_Android Emulator - Fatal编程技术网

如何在我的android表视图中以列的形式从数据库中获取数据,并根据页面显示将行数限制为10

如何在我的android表视图中以列的形式从数据库中获取数据,并根据页面显示将行数限制为10,android,android-layout,android-emulator,Android,Android Layout,Android Emulator,我已经完成了以下从表中导出数据的编码,并在android视图中显示为表的列和行 数据库编码为 public List<Country> getAllCountry() { List<Country> countryList = new ArrayList<Country>(); //select query String selectQuery = "SELECT * FROM COUNTRY_LIST"; SQLiteDa

我已经完成了以下从表中导出数据的编码,并在android视图中显示为表的列和行

数据库编码为

public List<Country> getAllCountry()
{
    List<Country> countryList = new ArrayList<Country>();

    //select query
    String selectQuery = "SELECT * FROM COUNTRY_LIST";

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);


    for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext())
    {
         Country country = new Country();
            country.setId(cursor.getString(0));
            country.setName(cursor.getString(1));
            country.setNationalty(cursor.getString(2));
            country.setDate(cursor.getString(3));


            // Adding person to list
            countryList.add(country);
    }

    return countryList;

}
<TableLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/tab">
  <TableRow
      >        
  </TableRow>    
</TableLayout>
List<Country> country = db.getAllCountry();

    StringBuilder builder = new StringBuilder();
    for (Country c: country)
    {               
        builder.append(c.getId()).append(";")
            .append(c.getName()).append(";")
            .append(c.getNationalty()).append(";")
            .append(c.getDate()).append("_");
    }
    //tv.setText(builder.toString());

    builder.toString();

    String st = new String(builder);
    Log.d("Main",st);
    String[] rows  = st.split("_");
    TableLayout tableLayout = (TableLayout)findViewById(R.id.tab);
    tableLayout.removeAllViews();

    for(int i=0;i<rows.length;i++){
        Log.d("Rows",rows[i]);
        String row  = rows[i];
        TableRow tableRow = new TableRow(getApplicationContext());
        tableRow.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        final String[] cols = row.split(";");

        Handler handler = null;

        for (int j = 0; j < cols.length; j++) {             
            final String col = cols[j];                                 
            TextView columsView = new TextView(getApplicationContext());
            columsView.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
            columsView.setTextColor(color.black);
            columsView.setText(String.format("%7s", col));                                
            Log.d("Cols", String.format("%7s", col));
            tableRow.addView(columsView);                
            }
         tableLayout.addView(tableRow);

    }
公共列表getAllCountry()
{
List countryList=new ArrayList();
//选择查询
String selectQuery=“从国家/地区列表中选择*”;
SQLiteDatabase db=this.getWritableDatabase();
Cursor Cursor=db.rawQuery(selectQuery,null);
对于(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext())
{
国家=新国家();
country.setId(cursor.getString(0));
country.setName(cursor.getString(1));
country.setNationalty(cursor.getString(2));
country.setDate(cursor.getString(3));
//将人员添加到列表中
国家列表。添加(国家);
}
返回国家列表;
}
XML是

public List<Country> getAllCountry()
{
    List<Country> countryList = new ArrayList<Country>();

    //select query
    String selectQuery = "SELECT * FROM COUNTRY_LIST";

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);


    for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext())
    {
         Country country = new Country();
            country.setId(cursor.getString(0));
            country.setName(cursor.getString(1));
            country.setNationalty(cursor.getString(2));
            country.setDate(cursor.getString(3));


            // Adding person to list
            countryList.add(country);
    }

    return countryList;

}
<TableLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/tab">
  <TableRow
      >        
  </TableRow>    
</TableLayout>
List<Country> country = db.getAllCountry();

    StringBuilder builder = new StringBuilder();
    for (Country c: country)
    {               
        builder.append(c.getId()).append(";")
            .append(c.getName()).append(";")
            .append(c.getNationalty()).append(";")
            .append(c.getDate()).append("_");
    }
    //tv.setText(builder.toString());

    builder.toString();

    String st = new String(builder);
    Log.d("Main",st);
    String[] rows  = st.split("_");
    TableLayout tableLayout = (TableLayout)findViewById(R.id.tab);
    tableLayout.removeAllViews();

    for(int i=0;i<rows.length;i++){
        Log.d("Rows",rows[i]);
        String row  = rows[i];
        TableRow tableRow = new TableRow(getApplicationContext());
        tableRow.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        final String[] cols = row.split(";");

        Handler handler = null;

        for (int j = 0; j < cols.length; j++) {             
            final String col = cols[j];                                 
            TextView columsView = new TextView(getApplicationContext());
            columsView.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
            columsView.setTextColor(color.black);
            columsView.setText(String.format("%7s", col));                                
            Log.d("Cols", String.format("%7s", col));
            tableRow.addView(columsView);                
            }
         tableLayout.addView(tableRow);

    }

活动编码为

public List<Country> getAllCountry()
{
    List<Country> countryList = new ArrayList<Country>();

    //select query
    String selectQuery = "SELECT * FROM COUNTRY_LIST";

    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);


    for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext())
    {
         Country country = new Country();
            country.setId(cursor.getString(0));
            country.setName(cursor.getString(1));
            country.setNationalty(cursor.getString(2));
            country.setDate(cursor.getString(3));


            // Adding person to list
            countryList.add(country);
    }

    return countryList;

}
<TableLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/tab">
  <TableRow
      >        
  </TableRow>    
</TableLayout>
List<Country> country = db.getAllCountry();

    StringBuilder builder = new StringBuilder();
    for (Country c: country)
    {               
        builder.append(c.getId()).append(";")
            .append(c.getName()).append(";")
            .append(c.getNationalty()).append(";")
            .append(c.getDate()).append("_");
    }
    //tv.setText(builder.toString());

    builder.toString();

    String st = new String(builder);
    Log.d("Main",st);
    String[] rows  = st.split("_");
    TableLayout tableLayout = (TableLayout)findViewById(R.id.tab);
    tableLayout.removeAllViews();

    for(int i=0;i<rows.length;i++){
        Log.d("Rows",rows[i]);
        String row  = rows[i];
        TableRow tableRow = new TableRow(getApplicationContext());
        tableRow.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        final String[] cols = row.split(";");

        Handler handler = null;

        for (int j = 0; j < cols.length; j++) {             
            final String col = cols[j];                                 
            TextView columsView = new TextView(getApplicationContext());
            columsView.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
            columsView.setTextColor(color.black);
            columsView.setText(String.format("%7s", col));                                
            Log.d("Cols", String.format("%7s", col));
            tableRow.addView(columsView);                
            }
         tableLayout.addView(tableRow);

    }
List country=db.getAllCountry();
StringBuilder=新的StringBuilder();
适用于(c国:国家)
{               
builder.append(c.getId()).append(;)
.append(c.getName()).append(;)
.append(c.getNationalty()).append(;)
.append(c.getDate()).append(“”);
}
//tv.setText(builder.toString());
builder.toString();
字符串st=新字符串(生成器);
日志d(“主”,st);
String[]行=st.split(“”);
TableLayout TableLayout=(TableLayout)findViewById(R.id.tab);
tableLayout.removeallview();
对于(int i=0;i
根据您的需要传递整数作为限制值

谢谢David,它很有效。如果我想看到接下来的10个值,我想做什么?请建议解决此问题。