私は空のLinearLayout
を持っています。それにTextView
の動的数値を追加する必要があります。私は以下のコードを使用した場合しかし、唯一の最初のTextView
が示されています:プログラムでテキストビューを追加
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] listofnumbers = new String[1000];
for (int i = 0 ; i < 1000 ; ++i) {
listofnumbers[i] = "null";
}
Context context = getBaseContext();
String text = null;
Uri uri = Uri.parse("content://sms");
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
String[] columnNames = cursor.getColumnNames();
LinearLayout lv = new LinearLayout(context);
LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, dip(48));
boolean v = true;
while (cursor.moveToNext())
{
String numberString = (cursor.getString(cursor.getColumnIndexOrThrow("address"))).replace(" ", "");
int i = 0;
boolean numberNotPresent = true;
for ( ; listofnumbers[i] != "null" ; ++i) {
if (numberString.equals(listofnumbers[i]) ) {
numberNotPresent = false;
}
}
if (numberNotPresent == true) {
text = (CharSequence) "From: " + cursor.getString(cursor.getColumnIndexOrThrow("address")) + ": " + cursor.getString(cursor.getColumnIndexOrThrow("body"));
listofnumbers[i] = numberString;
TextView tv = new TextView(this);
tv.setText(text);
tv.setLayoutParams(textViewParams);
lv.addView(tv);
}
}
setContentView(lv);
}
私が間違っている
?
あなたは 'if(numberNotPresent == true)'の条件が満たされていると確信していますか?おそらくいくつかのロギングを追加して、実際にそのコードに入っていて、別のTextViewを追加しようとしているのを確認してください。 – dldnh
もう一度条件を削除してもう一度チェックして、TextViewを取得した場合、そして、私は@dldnhと一緒にログをとるつもりです。 – noob
線形レイアウトのパラメータを設定します –