开发者

I have a dynamic text file and want to display its data in table View

I have a Text File on browser and I want to display textfile data in table view in android, in the text file multiple variables are there and separated by ,(coma) and variables value separated by |(pipe),, can anybody plz tell m开发者_如何学运维e how can access a specific variable value to show it is in table.


String text="";
String[] s;


text=readTxt();
final CharSequence cs = text;
        s=cs.toString().split("\\r?\\n? ?\t");
        s.toString().trim();

  for(int i=0;i<s.length;i++)
            {

                String temp=s[i].toString();
                if(temp.indexOf("yourlabel:")!=-1)
                {
                try {
                    temp=temp.substring(temp.indexOf("caption:")+8);
                    temp.trim();
                } catch (Exception e) {
                    // TODO: handle exception
                }

                    System.out.println("If temp values...."+i+"  "+temp);
                }
            }

 private String readTxt(){
     File mFile=new File("path/sample.txt");
     InputStream inputStream=null;
    try {
        inputStream = new FileInputStream(mFile);
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
     System.out.println(inputStream);
     ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

     int i;
  try {
   i = inputStream.read();
   while (i != -1)
      {
       byteArrayOutputStream.write(i);
       i = inputStream.read();
      }
      inputStream.close();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

     return byteArrayOutputStream.toString();
    }
}

this will read your text file, "if(temp.indexOf("yourlabel:")!=-1)" will gave you the specific tag value, try it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜