私はこのコードを使用しています
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);
textView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT
,LayoutParams.WRAP_CONTENT));
linearLayout.addView(textView);
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
このxmlコードで
<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>
文字列のこれらの部分をテーブルレイアウトに挿入して、テキストを印刷したときにきれいな列に表示されるようにします。これが機能する方法では、列に配置するのではなく、行の文字列行を出力するだけです。文字列に何行になるかわからないことを知っておくことも非常に重要です。したがって、50 og 100行になる可能性があるため、4つのテキストビューボックスを作成することはできません。したがって、iを作成する必要があります。テーブルビューのテキストビューボックスの数。iは行数です。しかし、私は常にこのエラーが発生し、呼び出しにはAPIレベル11が必要であり、APIレベル10を使用しています。この行が原因でエラーが発生しています
textView.setLayoutParams(newLayoutParams(LayoutParams.FILL_PARENT
,LayoutParams.WRAP_CONTENT));
これを機能させるためにどのような種類のparamlayoutオプションを使用できますか。