读取一个文件里面的几行数据,显示在一个TextView里面?这个怎么弄?
  is = asset.open("moreinformation.txt");
  br=new BufferedReader(new InputStreamReader(is,"GBK"));
  Map<String,String> map = new HashMap<String, String>();
  List<String> list = new ArrayList();
  String str = null;
  while ((str = br.readLine())!=null){
         //**********
  }
  data.add(map);
  }catch(IOException e){
  }
  finally{
     if(br!=null)try{br.close();}catch(IOException e){}
     if(is!=null)try{is.close();}catch(IOException e){}
  }
    SimpleAdapter adapter = new SimpleAdapter( this,data,R.layout.moreinformation_item,
       new String[]{"information"},new int[]{R.id.getmessage});
    lv.setAdapter(adapter);
}那个**** 里面我写了几个形式,但最后显示的时候都只有第一行出来了,是我写错了,还是这东西SimpleAdapter adapter 用错了,我是仿照读取多行,显示在多个textview里面写的?
求高手指导啊

解决方案 »

  1.   

    你把 Map<String,String> map = new HashMap<String, String>();
    放到while循环里试试
      

  2.   

    Map<String,String> map = new HashMap<String, String>();
    map.put("information", str);
    data.add(map);
    }
    这样?出是出来了,但是这就是有5个textview了,我只想放到一个textview里面啊
      

  3.   

    data.add(map)也放入while循环中试试看
      

  4.   

    TextView?  你把代码传多点吧, 都没看到TextView哦
      

  5.   

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">
      <TextView
       android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/getmessage"
      />
        <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="回帖"
      android:id="@+id/send_btn"
      />
     
    </LinearLayout>xml里是这样写的,用了那个while里面的代码后显示就是这样了
    …… 发帖
    …… 发帖
    ……发帖
    ……发帖
    我希望的是就是这样的显示结果
    …… 发帖
      

  6.   

    这样的话你把所有读出来的内容直接保存在一个String中不就行了么,map中就只有这一个元素,TextView支持自动换行的
      

  7.   

    StringBuffer sb2 = new StringBuffer();
    while ((str = br.readLine())!=null){
    sb2.append(str);
    }
    str = sb2.toString();
    map.put("information", str);
    data.add(map);谢了,搞定了