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

  • SEARCH
  • Home
  • 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 8918345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:43:40+00:00 2026-06-15T05:43:40+00:00

i am new to android java programming. I am adding a custom dynamic layout

  • 0

i am new to android java programming. I am adding a custom dynamic layout to a dialog box. i have 2 classes , Mainactivity.java and Getval.java
The Mainactivity.java create a dialoge and Getval generates dynamic layout at run time.
Every thing works good but when it tried to call Getval.java’s method, it gives an exception. here is the code of both classes.
The g.setval(); in Mainactivity.java cause problem.

                              :::::Mainactivity.java:::::

public class MainActivity extends Activity {

private Button button;
public Getval g=new Getval();
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    button= (Button) findViewById(R.id.buttonShowCustomDialog);
    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //set up dialog

            g.setval();
            Dialog dialog = new Dialog(MainActivity.this);
            dialog.setContentView(R.layout.attributewin);
            dialog.setTitle("Attribute Window");
            dialog.setCancelable(true);
            dialog.show();

    }
});

                                   ::::Getval::::

public class Getval extends Activity{

String names[]={"test","chaeck","kajsdhasj","dlasdig"};
String values[]={"test","chaeck","kajsdhasj","dlasdig"};
String test[]={"Attribut","Value"};

public void setval(){

TableLayout tl = (TableLayout) findViewById(R.id.tly);

Button b=new Button(this);

for (int i = 0; i < names.length; i++) {
//Row
    TableRow tr = new TableRow(this);
    tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
//TextViews
    TextView tv0 = new TextView(this);
    tv0.setText(names[i]);
    tv0.setMaxWidth(75);

    TextView tv1 = new TextView(this);
    tv1.setText(values[i]);
    tv1.setMaxWidth(150);

    View line = new View(this);
    line.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 1));
    line.setBackgroundColor(Color.BLACK);

//Setting Views
    tr.addView(tv0);
    tr.addView(tv1);
    tl.addView(tr);
    tl.addView(line);

}
//Button Row
    TableRow tr = new TableRow(this);
    tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
    tr.setGravity(0x11);
    b.setId(100);
    b.setText("Return");
    b.setGravity(0x11);
    tr.addView(b);
    tl.addView(tr);

}
}

  • 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-06-15T05:43:41+00:00Added an answer on June 15, 2026 at 5:43 am

    Looking over this without seeing your xml or complete code (or exception that is thrown), I would be willing to guess that you are trying to inflate/modify a view (R.id.tly) from an activity other than the one where it was originally inflated from (MainActivity).

    Generally speaking, you can’t do this without doing some tricks with cross activity handlers or other methods. Perhaps change your code to inflate the views (R.id.tly) in MainActivity (and in your dialog if it is inside of R.layout.attributewin), do your processing in Getval, return them to MainActivity so it can populate the views.

    But again, this is just a guess, since I don’t see your xml or exception.

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

Sidebar

Related Questions

I am new to Android/Java programming. I have two classes, one is an Activity
I am new to Android and Java programming. I have a class which implements
I'm new to Android & Java programming but have been programming in .NET for
I am new to Android/java programming. I really have no clue what I am
I'm new to Android and Java programming and I've manage to create a simple
I'm new to Android programming however I do have some Java experience. What I
I am new to Java programming / Android development - but I have been
I'm fairly new to Android programming and to Java in general, but I have
I'm new to android and I have not done any Java programming for probably
I am new at android development and java programming, but I have decided to

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.