Android如何显示sd卡中的文本文件并逐个显示文本

Android如何显示sd卡中的文本文件并逐个显示文本,android,textview,android-sdcard,Android,Textview,Android Sdcard,我的sd卡上有一个文本文件,其中包含以下数据: Farhan shah Noman Shah Ahmad shah Mohsin shah Haris shah 我的应用程序中有一个TextView,现在我想在运行我的应用程序时,我的TextView只显示第一个名字“Farhan Shah”,x秒后显示“Noman Shah”等等。。 但现在当我运行我的应用程序时,它会读取所有文本并显示在我的文本视图中。 非常感谢您的帮助,谢谢 这是我的代码: File sdcard = Environmen

我的sd卡上有一个文本文件,其中包含以下数据:

Farhan shah
Noman Shah
Ahmad shah
Mohsin shah
Haris shah
我的应用程序中有一个
TextView
,现在我想在运行我的应用程序时,我的
TextView
只显示第一个名字“Farhan Shah”,x秒后显示“Noman Shah”等等。。 但现在当我运行我的应用程序时,它会读取所有文本并显示在我的文本视图中。 非常感谢您的帮助,谢谢

这是我的代码:

File sdcard = Environment.getExternalStorageDirectory();

    //Get the text file
    File file = new File(sdcard,"test.txt");

    //Read text from file
    StringBuilder text = new StringBuilder();

    try {
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line;

        while ((line = br.readLine()) != null) {
            text.append(line);
            text.append('\n');
        }
    }
    catch (IOException e) {
        //You'll need to add proper error handling here
        e.printStackTrace();
    }

    t = new TextView(this);
    t = (TextView) findViewById(R.id.tv_textlist);
    t.setText(text);

这是因为在将textview设置为其内容之前,您将整个文件读入文本

试着这样做:

File sdcard = Environment.getExternalStorageDirectory();

//Get the text file
File file = new File(sdcard,"test.txt");

//Read text from file
StringBuilder text = new StringBuilder();

BufferedReader br = new BufferedReader(new FileReader(file));
TextView t = (TextView) findViewById(R.id.tv_textlist);
Timer mTimer = new Timer();

TimerTask Next = new TimerTask() {
    @Override
    public void run() {
        try {
                    String line = br.readLine();
                    if(line!= null)
                        t.setText(line);
                    else
                        mTimer.cancel();
                } catch (IOException e) {

                }   
    }
};

mTimer.scheduleAtFixedRate(Next,100L,TimeXinMillis);
而不是text.append('\n');添加一些分隔符,如text.append(“|”); 稍后将其拆分为字符串数组并循环

t = (TextView) findViewById(R.id.tv_textlist);
text.append('|');
String[] splitText = text.toString().split("|");
for(int i = 0; i < splitText.length; i++) {
 t.setText(splitText[i]);
}
t=(TextView)findViewById(R.id.tv\u textlist);
text.append(“|”);
String[]splitText=text.toString().split(“|”);
for(int i=0;i
这是一个怎样的答案?
textnames
来自哪里?
try {
  BufferedReader br = new BufferedReader(new FileReader(file));
  String line;

  while ((line = br.readLine()) != null) {

   textnames.add(line);
      text.append(line);
      text.append('\n');
  }
       }
catch (IOException e) {

e.printStackTrace();
}