Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7535487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:18:47+00:00 2026-05-30T06:18:47+00:00

I am new to Android.I have created a dynamic textview which is displayed on

  • 0

I am new to Android.I have created a dynamic textview which is displayed on emulator,
but i am not adding this textview using addView then how it displayed?

Here is my code:

package com.DynamicTextField;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class DynamicTextFieldActivity extends Activity {
    /** Called when the activity is first created. */
    private TextView tv ;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        tv = new TextView(this);
        tv.setText("Dynamic Text View Test\n");
        tv.setTextSize(18);
        setContentView(tv);
    }
}

What is the best way of adding textview?

Can anyone help!

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:18:49+00:00Added an answer on May 30, 2026 at 6:18 am

    Simple. addView can be called to add a View to a ViewGroup (a View capable of containing other Views). In your example, you are inside of an Activity and you are calling setContentView which sets the content to anything that extends View.

    The normal way to use views in an activity is to either define your viewgroup in xml or programatically. If you do it programatically it would look something like:

    RelativeLayout layout = new RelativeLayout(context);
    TextView tv = new TextView(context);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(200, 200);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    tv.setLayoutParams(params);
    layout.addView(tv);
    

    Normally you would define the View in it’s own class. But if you’d like you can do this all in onCreate of your activity, and use “this” in place of context.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Android development, I have created an animation which I have associated
I'm quite new to android, but I have already created several apps and published,
I have created a custom title bar as shown in this example http://staticallytyped.wordpress.com/2011/03/18/android-dynamic-and-custom-title-bars/ A
I am new to Android development. I have created a main Activity (->A), which
Ok, im fairly new to android but i have managed to teach myself the
I have this code on my Android phone. URI uri = new URI(url); HttpPost
I am new to android. I have to add table row in a dynamic
I have Android application which is Sales Rep application.When he using the app first
I have created a Java code for my Android App. String[] MovieName=new String[]{}; for
i have created a coverflow using the code given by http://android.jmsliu.com/138/android-infinite-loop-gallery.html . And it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.