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

The Archive Base Latest Questions

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

I have an activity that shows customer information. All the controls are drawn dynamically

  • 0

I have an activity that shows customer information. All the controls are drawn dynamically as the design for the screen is controlled by a central SQL database. (IE screen position, editable and mandatory) so there is no XML for the design.

Now so far everything I have done has worked very well until I came to try adding a ListView object to list the customers communication data. (IE a list of phone numbers, emails, fax numbers or website URLs)

This List view is added correctly and the first row of data is displayed but I cannot seem to get the anymore rows to display.

The items are added into a table row and these are then added onto a table layout. Could this be the problem? However when adding the ListView item this is first added to a RelativeLayout item so this should allow more than one line to be displayed?!

Any Ideas why this could be occurring? I have checked the values of my array and I definitely have more than one item in it.

The following is the Activities onCreate method:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    model = SharedModel.getInstance();
    dbHelper = new DatabaseHelper(this);

    LinearLayout baseLayout = new LinearLayout(this);
    baseLayout.setOrientation(LinearLayout.VERTICAL);

    // add the customer name and number field.
    // NOTE: We will always require this widget regardless of dialog design fields
    tvCustomerNameNumber = new TextView(this);
    tvCustomerNameNumber.setTextSize(20);
    baseLayout.addView(tvCustomerNameNumber);

    // buttons
    RelativeLayout.LayoutParams alignBotton = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
    LinearLayout buttons = new LinearLayout(this);
    buttons.setOrientation(LinearLayout.HORIZONTAL);
    alignBotton.addRule(RelativeLayout.ALIGN_BOTTOM, baseLayout.getId());

    // button edit
    Button edit = new Button(this);
    edit.setId(EDIT_BUTTON_ID);
    edit.setText(dbHelper.getActivityString(dbHelper.getWritableDatabase(), model.getUserLang().getLanguage().GetCodeId(), "buttonEdit", 1001000));
    edit.setOnClickListener(new View.OnClickListener() {            
        public void onClick(View v) {
            setButtonsEnabled(false, true, true);
            setControlsEnabled(true);
        }
    });
    buttons.addView(edit);

    // button save
    Button save = new Button(this);
    save.setId(SAVE_BUTTON_ID);
    save.setText(dbHelper.getActivityString(dbHelper.getWritableDatabase(), model.getUserLang().getLanguage().GetCodeId(), "buttonSave", 1001000));
    save.setOnClickListener(new View.OnClickListener() {            
        public void onClick(View v) {
            try {
                saveCustomer();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
    buttons.addView(save);

    // button cancel
    Button cancel = new Button(this);
    cancel.setId(CANCEL_BUTTON_ID);
    cancel.setText(dbHelper.getActivityString(dbHelper.getWritableDatabase(), model.getUserLang().getLanguage().GetCodeId(), "buttonCancel", 1001000));
    cancel.setOnClickListener(new View.OnClickListener() {          
        public void onClick(View v) {
            try {
                cancelChanges();
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
    buttons.addView(cancel);

    // add the buttons
    baseLayout.addView(buttons);

    // build up the table of controls
    TableLayout tl = new TableLayout(this);

    // get the dialog design json array for customer information
    dialogFields = model.getDialogDesignFields();   

    // reset the field type indexes
    addedIndexes = new ArrayList<Integer>();
    addedCodeIndexes = new ArrayList<Integer>();
    addedDateIndexes = new ArrayList<Integer>();
    addedTextIndexes = new ArrayList<Integer>();
    addedListIndexes = new ArrayList<Integer>();
    mandatoryIndexes = new ArrayList<Integer>();

    // for each control in the array
    for(int i=0;i<=model.getDialogDesignFields().length() - 1; i++) {
        try {
            // if the control is for the customer page
            if(dialogFields.getJSONObject(i).get("formname").equals("CustomerInformation")){
                handleField(tl, dialogFields.getJSONObject(i));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }       

    // Scroll view.
    // NOTE: We will always need this widget to enable us to scroll the page
    // if too many items are added for the display size
    ScrollView sv = new ScrollView(this);
    sv.addView(tl);
    baseLayout.addView(sv);

    // set the content view
    this.setContentView(baseLayout);
    // make sure we are not in edit mode
    setButtonsEnabled(true, false, false);
    setControlsEnabled(false);
    setResult(0); 
}

And now the handleField method that decides what to do with the field im adding:

private void handleField(TableLayout tl, final JSONObject field) throws JSONException {

    // get field index
    int id = field.getInt("viewindex") + 1;
    final String name = field.getString("name");

    // if the name = CustomerAddressID don't do anything
    if(name.equals("CustomerAddressID") != true) {
        // if the name is not equal to CustomerCommunicationID
        if(name.equals("CustomerCommunicationID") == false) {
            if(id > 0) {
                // create and add controls
                // add the field index to the 
                addedIndexes.add(id);
                // layout parameters
                RelativeLayout.LayoutParams alignRight = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

                // if the field is mandatory
                if(field.getInt("mandatory") == 1) {
                    TextView mandatory = new TextView(this);
                    mandatory.setText("*");
                    tl.addView(mandatory);
                    mandatoryIndexes.add(id);
                }           

                // field name description
                TextView fn = new TextView(this);
                fn.setId(id + 1000);
                fn.setText(dbHelper.getActivityString(dbHelper.getWritableDatabase(), model.getUserLang().getLanguage().GetCodeId(), name, 1000030));
                tl.addView(fn);             

                // create a table row 
                TableRow tr = new TableRow(this);
                tr.setId(id + 10000);
                tl.addView(tr);

                // create a relative layout
                RelativeLayout rl = new RelativeLayout(this);
                rl.setId(id + 100000);
                rl.setTag(field);
                rl.setBackgroundResource(R.drawable.myborder);

                // if the control is not disabled
                if(field.getInt("disabled") == 0) {

                    // so we are adding a listener
                    // if the name is code we are adding to code indexes 
                    if(name.endsWith("CODE") == true | name.equals("PreferredVisitDay")) {                      
                        addedCodeIndexes.add(id);
                    } else if (name.endsWith("DATE") == true) {
                        addedDateIndexes.add(id);                       
                    } else {
                        addedTextIndexes.add(id);
                    }           

                    // add a listener
                    rl.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            // show the code picker for customer group
                            JSONObject field = (JSONObject) v.getTag(); 
                            try {
                                prepareDialog(field);
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }                               
                        }
                    });

                    // image view           
                    ImageView iv = new ImageView(this);
                    iv.setId(id + 1000000);
                    iv.setImageResource(R.drawable.edit16x16);
                    iv.setVisibility(View.GONE);
                    alignRight.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, iv.getId());
                    rl.addView(iv, alignRight);
                }                   

                tl.addView(rl);
                // fieldValue
                TextView fv = new TextView(this);
                fv.setId(id + 10000000);
                fv.setTextSize(18);
                rl.addView(fv);

            }
        } else {
            if(id > 0) {
                addedIndexes.add(id);

                // field name description
                TextView fn = new TextView(this);
                fn.setId(id + 1000);
                fn.setText(dbHelper.getActivityString(dbHelper.getWritableDatabase(), model.getUserLang().getLanguage().GetCodeId(), name, 1000030));
                tl.addView(fn);             

                // create a table row 
                TableRow tr = new TableRow(this);
                tr.setId(id + 10000);
                tl.addView(tr);

                // create a relative layout
                RelativeLayout rl = new RelativeLayout(this);
                rl.setId(id + 100000);
                rl.setTag(field);
                rl.setBackgroundResource(R.drawable.myborder);

                tl.addView(rl);
                // list view
                ListView lv = new ListView(this);
                lv.setId(id + 10000000);
                lv.setTag(field);
                lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
                        try {
                            communicationClicked(arg0, view, position, id, field);
                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }           
                    }
                });
                rl.addView(lv);
            }               
        }
    }
}

The ListView Item is added in the second block of code with the following code:

// list view
ListView lv = new ListView(this);
lv.setId(id + 10000000);
lv.setTag(field);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
        try {
            communicationClicked(arg0, view, position, id, field);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }           
    }
});
rl.addView(lv);

Finally the List view is populated with the following code:

} else if (name.equals("CustomerCommunicationID")){
    // set communications value
    ListView lv = (ListView)findViewById(index + 10000000);
    // create an array adapter with the customer type data array
    ArrayAdapter<Communication> communicationAdapter = new ArrayAdapter<Communication>(this, R.layout.communication_menu_item, currentCustomer.getCustomerCommunications());
    // assign the my customers list control the array adapter
    lv.setAdapter(communicationAdapter);
    Log.i(TAG, "Communications Assigned");
} else {

I have done a test and added a Listview at the top of my application and set the listadapter to my array and all the lines are displayed.

So looks like Its to do with the Table rows

  • 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-30T09:33:19+00:00Added an answer on May 30, 2026 at 9:33 am

    After doing some research I have found that its not good practice to place a ListView inside a another scrollable item.

    The following link discusses this:

    Google I/O 2010 – The world of ListView

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

Sidebar

Related Questions

I have an activity that shows up when the phone screen goes to sleep/turns
I Have activity that get some data from the internet, and shows it to
I have a little function that shows latest activity, it grab timestamp in unix
i have problems with my game. I have an Main Activity that's shows a
I want my app to have an activity that shows instruction on how to
I have a map view activity that shows a few OverlayItems . In the
I have a activity on my app, that shows a lot of options that
I have created an Activity that shows a listview and on swipe action another
Basically, I have a field in my table that shows when the latest activity
I have recently built an application that shows you a camera preview on screen.

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.