2012-11-03 1 views
0

나는이 XML 레이아웃이 코드정확한 수의 textview를 만들고이를 tableview에 저장하는 방법은 무엇입니까?

public class MainActivity extends Activity { 

    TextView textview; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 


    String hallo = "blabla " + "jojo " + "lol " + "\n" + "doj " + "drasl " + "\n"; 
    InputStream is = new ByteArrayInputStream(hallo.getBytes()); 
    BufferedReader in = new BufferedReader(new InputStreamReader(is)); 
    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout); 

    String line; 
    try { 
     while ((line = in.readLine()) != null) { 
      String[] RowData = line.split(" "); 
      String eitt = RowData[0]; 
      String tvo = RowData[1]; 

      TextView textView = new TextView(this); 
      textView.setText(line); 

      linearLayout.addView(textView); 
     } 
    } catch (IOException e1) { 
     e1.printStackTrace(); 
    } 
} 
} 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/scrollView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:id="@+id/linearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     </LinearLayout> 

</ScrollView> 

텍스트 내 조각을 인쇄 할 때 나올 수 있도록 나는, 테이블 레이아웃에 문자열이 부분을 삽입 할 좋은 칼럼에. 이 방법은 열에 넣는 대신 줄의 줄을 인쇄하기 만합니다. 문자열에 몇 줄이 있는지도 모르기 때문에 텍스트 줄 수를 4 줄까지 늘릴 수는 없습니다. 그래서 50 줄에 100 줄이 생길 수 있습니다. 그래서 i를 ​​만들 필요가 있습니다. setLayoutParamsTextView에 추가하여 전 라인

답변

2

시도 수있는있는 테이블보기에서 텍스트 뷰 상자의 양 : 나는이 시도,하지만 난이 오류가 발생했습니다

//Your code... 
String line; 
    try { 
     while ((line = in.readLine()) != null) { 
      String[] RowData = line.split(" "); 
      String eitt = RowData[0]; 
      String tvo = RowData[1]; 

      TextView textView = new TextView(this); 
      textView.setText(line); 
      textView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT 
      ,LayoutParams.WRAP_CONTENT)); 
      linearLayout.addView(textView); 
     } 
    } catch (IOException e1) { 
     e1.printStackTrace(); 
    } 

//Your code... 
+0

는, 호출 API 레벨 내가 11이 필요 API 10을 사용합니다.이 오류는 FILL_PARENT에 대한 것입니다. 내가 그것에 대해 무엇을 할 수 있는지 알고 있습니까? – davidhlynsson

+0

그러면 다른 LayoutParams 옵션을 사용할 수 있습니다. LayoutParams.wrap_content 또는 LayoutParams.fill_parent –

+0

wrap_content, fill_parent, match_parent를 사용하려고하면 모든 것이 samt 오류를 발생시킵니다. xml 파일에서 뭔가를 변경해야합니까? – davidhlynsson

관련 문제