私は、TextViewを次のように動的に追加しようとしています。しかし、私はアプリケーションを実行した後、私の新しいTextViewを見ることができません。動的にTextViewをアクティビティに追加する
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
TextView textView= (TextView) new TextView(this);
textView.setText("Hello");
textView.setBackgroundColor(0xff66ff66); // hex color 0xAARRGGBB
textView.setPadding(20, 20, 20, 20);
LinearLayout ll = (LinearLayout)findViewById(R.id.LinearLayout1);
textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
ll.addView(textView);
ViewGroup vg = (ViewGroup) findViewById (R.id.LinearLayout1);
vg.invalidate();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
databaseHelper = new DatabaseHelper(getBaseContext());
try {
databaseHelper.createDataBase();
} catch (IOException e) {
e.printStackTrace();
}
databaseHelper.openDataBase();
}
これらの2行を削除しました。まだ "こんにちは"が表示されません。 –