0

I want to add Text-view at run time on Android to display the contents of my database on a activity,which can change every time. Please Help

Bharat Lalwani
  • 1,277
  • 15
  • 17
  • You need to be more specific and describe better what you are trying to do. You should also describe what you have tried so far, including posting some code. – Karakuri Jul 01 '15 at 06:43
  • possible duplicate of [How can I add a TextView to a LinearLayout dynamically in Android?](http://stackoverflow.com/questions/4203506/how-can-i-add-a-textview-to-a-linearlayout-dynamically-in-android) – Keyur Lakhani Jul 01 '15 at 06:51

1 Answers1

2

You could create a TextView dynamically like this for example:

//create a TextView with Layout parameters according to your needs
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//if your parent Layout is relativeLayout, just change the word LinearLayout with RelativeLayout
TextView tv=new TextView(this);
tv.setLayoutParams(lparams);
tv.setText("test");
//get the parent layout for your new TextView and add the new TextView to it
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll_example);
linearLayout.addView(tv);

And in the tv.setText(...); line you could set the text, that your got from your database.

Gabriella Angelova
  • 2,985
  • 1
  • 17
  • 30