Android having problems displaying data

Go To StackoverFlow.com

0

So I have 5 columns in a relative layout, I then read data from a csv file and put the data I need in the corresponding column. My code for this is the following:

 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.past_results);

    final global gs = (global)getApplication();
    AlertDialog enter_alert = new AlertDialog.Builder(past_results.this).create();
    List<String[]> values = gs.read_csv();

    if(values==null){
            enter_alert.setTitle("Failed To Read");
            enter_alert.setMessage("Unable to Read File");
            enter_alert.setButton("Close", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {}
            });
            enter_alert.show();
    return;
    }

    else{


        for(int i=3;i<values.size();i++){
           //loops through all the rows in the file first 3 rows are not needed
           String date = values.get(i)[0].toString();//get the date value
           String sn = values.get(i)[9].toString();//get the Unit S/N
           String fzero = values.get(i)[10].toString();//get the f_zero value
           String foffset = values.get(i)[11].toString();//get the f offset value
           String ffactor = values.get(i)[12].toString();//get the f factor value
           TextView datetext=new TextView(this);
           TextView sntext=new TextView(this);
           TextView fzerotext=new TextView(this);
           TextView foffsettext=new TextView(this);
           TextView ffactortext=new TextView(this);

           datetext.setText(date);
           datetext.setId(1+(i-3)*5);   //is this the right way to make an id?
           datetext.setTextSize(15);

           sntext.setText(sn);
           sntext.setId(2+(i-3)*5);
           sntext.setTextSize(15);

           fzerotext.setText(fzero);
           fzerotext.setId(3+(i-3)*5);
           fzerotext.setTextSize(15);

           foffsettext.setText(foffset);
           foffsettext.setId(4+(i-3)*5);
           foffsettext.setTextSize(15);

           ffactortext.setText(ffactor);
           ffactortext.setId(5+(i-3)*5);
           ffactortext.setTextSize(15);



           RelativeLayout.LayoutParams dateparams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
          RelativeLayout.LayoutParams snparams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
           RelativeLayout.LayoutParams fzeroparams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
           RelativeLayout.LayoutParams foffsetparams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
           RelativeLayout.LayoutParams ffactorparams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

           dateparams.addRule(RelativeLayout.ALIGN_LEFT,R.id.past_date);
           snparams.addRule(RelativeLayout.ALIGN_LEFT,R.id.past_sn);
           fzeroparams.addRule(RelativeLayout.ALIGN_LEFT,R.id.past_f_zero);
           foffsetparams.addRule(RelativeLayout.ALIGN_LEFT,R.id.past_f_offset);
           ffactorparams.addRule(RelativeLayout.ALIGN_LEFT,R.id.past_f_factor);

           if (i==3){


               dateparams.addRule(RelativeLayout.BELOW,R.id.past_date);
              snparams.addRule(RelativeLayout.BELOW,R.id.past_sn); 
               fzeroparams.addRule(RelativeLayout.BELOW,R.id.past_f_zero);
               foffsetparams.addRule(RelativeLayout.BELOW,R.id.past_f_offset);
               ffactorparams.addRule(RelativeLayout.BELOW,R.id.past_f_factor);
           }
           else{
               dateparams.addRule(RelativeLayout.BELOW,1+(i-3)*5);
               snparams.addRule(RelativeLayout.BELOW,2+(i-3)*5); 
               fzeroparams.addRule(RelativeLayout.BELOW,3+(i-3)*5);
               foffsetparams.addRule(RelativeLayout.BELOW,4+(i-3)*5);
               ffactorparams.addRule(RelativeLayout.BELOW,5+(i-3)*5);
           }
          datetext.setLayoutParams(dateparams);
          sntext.setLayoutParams(snparams);
          fzerotext.setLayoutParams(fzeroparams);
          foffsettext.setLayoutParams(foffsetparams);
          ffactortext.setLayoutParams(ffactorparams);

       }//end of for loop
    }//end of if


    };

}

right now the result is just nothing is being displayed so I have a suspicion that this is due to how I am setting the parameters as when I was debugging I can see the values in the list. Do you see what I am doing wrong?

2012-04-04 18:08
by yawnobleix
Have you considered using an XML layout - JRaymond 2012-04-04 18:16
I have but I am unsure how I would do that when I need to add an unknown number of values in each colum - yawnobleix 2012-04-04 18:18
Where are you adding your new TextViews to your layout - Simon 2012-04-04 18:25
Use a listView and a custom ArrayAdapter - it's what they're for. But @Simon is right - I don't see you adding the textViews to the layout anywhere (mRelativeLayout.addView(dateText); ... - JRaymond 2012-04-04 18:28


0

The reason nothing is being displayed is that you are calling

setContentView(R.layout.past_results);

at the beginning, this is telling the system that you want to display the layout located in the past_results.xml file.

If you want to get your newly created TextViews onto the screen you'd have to acquire a reference to your parent layout from that xml file. Then you make calls like this

relLayout.addView(datetex);
relLayout.addView(sntext);
etc...

However as JRaymond pointed out the preferred way to accomplish something like this would be with some kind of Adapter that you create specifically to show the data exactly how you want. It will take away a lot of the hassle of trying to hardcode creation for all of your individual views and populate them "by hand"

2012-04-04 18:34
by FoamyGuy
Ads