即时添加文本视图

时间:2011-02-21 05:49:26

标签: android

我目前正在尝试将从SD卡中的文件中获取的每个字符分配到不同的文本视图

有人可以建议我怎么做?

我不确定即时添加文本视图

        try {
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line="";
        int c,counter=0;
        while ((c = br.read()) != -1) {
            line+=(char)c;
            counter++;              
        }
        char[] singleText = line.toCharArray();
        for (int i = 1; i < counter; i++)
        {
            //text.append(singleText[i]);
        }
    }
    catch (IOException e) {
        //You'll need to add proper error handling here
    }

    //Find the view by its id
    TextView tv = (TextView)findViewById(R.id.TextView01);

    //Set the text
    tv.setText(text);

我已经做了一个计数器来计算应添加多少文本视图以及将字符分配到数组中但我似乎无法找到代码为动态中的每个字符添加特定大小的textview

先谢谢

1 个答案:

答案 0 :(得分:0)

你的意思是这段代码?

TextView text = new TextView(this);  
text .setText(questionStatement);  
text .setLayoutParams(new LayoutParams(  
                        LayoutParams.WRAP_CONTENT,  
                        LayoutParams.WRAP_CONTENT));  

同样,您可以使用所有这些lovely api's。要在布局中添加文字视图,您必须使用addView()