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 8828921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:42:59+00:00 2026-06-14T07:42:59+00:00

I am creating some buttons pragmatically. Using the same code from 2 different activities

  • 0

I am creating some buttons pragmatically. Using the same code from 2 different activities the button fires are not working on one of the activities. I am a little perplexed as to what I must be overlooking.

public class Home_Page_Activity extends Activity {

JSONArray nameArray;
JSONArray valArray;
String[] arrayButtonTitles;
String font;
Context context = null;
LinearLayout.LayoutParams params_textview;
LinearLayout.LayoutParams params_button;
LinearLayout.LayoutParams params_linearlayout;
LinearLayout home_page_layout;
OnClickListener myListener;
Typeface face;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_page_activity);
    WebView wv_Welcome_Message = (WebView) findViewById(R.id.wv_Welcome_Message);

    context = getApplicationContext();
    params_linearlayout = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
    params_linearlayout.gravity = Gravity.CENTER;
    // Set Font
    font = "fonts/aescrawl.ttf";
    face = Typeface.createFromAsset(getAssets(), font);

    // Reference Layout
    home_page_layout = (LinearLayout) findViewById(R.id.home_page_layout);

    // Set Layout Parameters for XML Elements. (Height, Width,
    // Weight,Padding)
    params_button = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, 32, 1.0f);
    params_button.setMargins(10, 0, 10, 30);

    // Load webview if there is connectivity
    if (Repeatables.isNetworkAvailable(context) == true) {
        new InitTask().execute();
    } else {
        wv_Welcome_Message.setVisibility(View.GONE);
    }

    String[] arrayButtonTitles = { "Sub 1", "Sub 2", "Final 1", "Final 2",
            "Category 5", "Category 6", "Category 7", "Category 8",
            "Category 9", "Category 10" };
    Load_Main_Menu(arrayButtonTitles);

myListener = new OnClickListener() {
          public void onClick(View v) {
            Object tag = v.getTag();
            // Do something depending on the value of the tag

                Log.e("TAG","Button "+tag+" pushed");
              if("0".equals(tag.toString())){
                  Log.e("TAG","Hello 1");
              }else  if("21".equals(tag.toString())){
                    Intent i = new Intent(getApplicationContext(), Sub_Menu_Categories_Main_Activity.class);
                    i.putExtra("whatSubMenuToLoad","none");
                    i.putExtra("whatScreenTypeToLoad","FINALCATEGORY");
                    i.putExtra("categoryId","313");
                    startActivity(i);
              }
          }
        };

}

// Build Home Page XML Layout
public void Load_Main_Menu(String[] buttons) {

    arrayButtonTitles = buttons;
    int numberOfButtons = arrayButtonTitles.length;
    LinearLayout[] ll = new LinearLayout[numberOfButtons];

    // Add Elements to Layout
    for (int i = 0; i < numberOfButtons; i++) {

        Button btn = new Button(this);
        btn.setText(arrayButtonTitles[i]);
        btn.setTag(i);
        btn.setOnClickListener(myListener);
        btn.setTypeface(face);
        btn.setTextSize(18);
        btn.setTextColor(context.getResources().getColor(
                R.color.all_button_font_color));
        btn.setBackgroundResource(R.drawable.category_button_background_shape);
        if (i % 2 == 0) {
            ll[i] = new LinearLayout(this);
            ll[i].setOrientation(LinearLayout.HORIZONTAL);
            ll[i].addView(btn, params_button);
            home_page_layout.addView(ll[i], params_linearlayout);
        } else {
            ll[i - 1].addView(btn, params_button);
        }
    }
}
}
  • 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-14T07:43:00+00:00Added an answer on June 14, 2026 at 7:43 am

    You haven’t initialized myListener, there is nothing to fire… Oops 🙂

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

Sidebar

Related Questions

I've written some code for a button action. First I'm creating a button UI
got this code from a website that helped me in creating buttons and stuff.
I have an array of radio button from where i am creating radio buttons
I'm creating some JButtons from a String array for a menu. Those buttons are
I'm creating a Dialog window with some button controls. I want the buttons to
I am creating one form which contain table and some buttons. A picture is
I'm creating some 50 button dynamically. Text is getting set as followed: btn.Text=result.Rows[i]["Col1"].ToString()+"\n"+result.Rows[i]["Col2"].ToString() +"\n"+result.Rows[i]["Col3"].ToString();
I'm creating some basic OO scripts using MySQLi and getting an Undefined Method error
I am creating some PDF reports using iText in Java. According to the requirements,
I'm new to this iPad business, and I'm creating some buttons inside a scrollview

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.