Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.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_Android Layout_Dynamic_Textview - Fatal编程技术网

用android动态显示数据

用android动态显示数据,android,android-layout,dynamic,textview,Android,Android Layout,Dynamic,Textview,我已经编写了一个布局文件来显示从查询数据库中获得的数据。但是,如何在文本视图中播放数据呢?其目的是显示动态内容,而不是资源文件中预定义的静态内容 t.setText(j); 我真的不想写 TextView x = new TextView(); x.setText("..."); x.setGravity(""); x... t.setText(j); 因为这是非常重复的,我必须重做我想要显示的所有数据,而且我已经在xml文件中格式化了所有内容 t.setText(j);

我已经编写了一个布局文件来显示从查询数据库中获得的数据。但是,如何在文本视图中播放数据呢?其目的是显示动态内容,而不是资源文件中预定义的静态内容

t.setText(j);  
我真的不想写

 TextView x = new TextView();
 x.setText("...");
 x.setGravity("");
 x...
t.setText(j);  
因为这是非常重复的,我必须重做我想要显示的所有数据,而且我已经在xml文件中格式化了所有内容

t.setText(j);  
我的数据库函数调用返回一个游标对象,我想我可以使用

SimpleCursorAdapter();
t.setText(j);  
但我似乎找不到将此发送到textview的文档

t.setText(j);  

有人有什么建议吗?

比如说,您有一个用XML定义的文本视图,id为tv

t.setText(j);  
TextView t=(TextView)findviewbyd(R.id.tv)

t.setText(j);  
并希望在从数据库查询后为其设置文本

t.setText(j);  
假设您有一个包含两列a和B的表,并使用如下查询:

  String q = "SELECT * FROM table_name where(your_condition)";
  Cursor c = db.rawQuery(q, null);
t.setText(j);  
假设您想使用列A的值,可以使用
c.getString(c.getColumnIndex(“A”))找到该值

t.setText(j);  
使用光标c,如下所示:

  if(c.getCount() == 0)
                  {

            //no data found
                  }
                  else  {
                      String j="";
                      c.moveToFirst();
                      do {
                          String cm = c.getString(c.getColumnIndex("A"));
                                             j = j+cm;   
                          } while (c.moveToNext());
                      c.close();
t.setText(j);  
现在将此文本设置为文本框(动态:D):

t.setText(j);  

这是一个完整的示例:由我提供(使用简单的方法),您可以尝试

t.setText(j);