-1

I know that it might be a simple solution for this but I am not able to figure it out. I want to set the first view on the viewflipper to be the one which was found true in if statement. Heres the code, which is inside a while loop:

String itrstr = itr.next();
RelativeLayout rl = new RelativeLayout(this);
TextView titletv= new TextView(this);
TextView bodytv = new TextView(this);
            
if(itrstr.equalsIgnoreCase(titlestr)){
    titletv.setText(Html.fromHtml(itrstr));
    titletv.setPadding(0, 0, 0, 0);
    bodytv.setText(Html.fromHtml(news.get(itrstr)));
    titletv.setId(count);
    bodytv.setPadding(0, 50,0, 0);
    rl.addView(titletv);
    rl.addView(bodytv);
    rl.setId(1);
 }else{    
        titletv.setText(Html.fromHtml(itrstr));
        titletv.setPadding(0, 0, 0, 0);
        bodytv.setText(Html.fromHtml(desc.get(count)));
        titletv.setId(count);
        bodytv.setPadding(0, 50,0, 0);
        rl.addView(titletv);
        rl.addView(bodytv);
        rl.setId(2+count);
  }
 vf.addView(rl);
 count++;

Thanks

Edit-1

I solved this by adding the matched title and body before looping through them, but I am getting an empty screen in between the matched view and the rest of the views.

titletv.setText(Html.fromHtml(titlestr));
        titletv.setPadding(0, 0, 0, 0);
       bodytv.setText(Html.fromHtml(news.get(titlestr)));
      
        titletv.setId(count);
        bodytv.setPadding(0, 50,0, 0);
        
        bodytv.setHorizontalScrollBarEnabled(true);
        bodytv.setVerticalScrollBarEnabled(true);
        bodytv.setMovementMethod(new ScrollingMovementMethod());
        rl.addView(titletv);
        rl.addView(bodytv);
        rl.setId(1);
        vf.addView(rl);
        
      //add the view 
      while(itr.hasNext()){
          //Log.i("ArrayList: "+Integer.toString(count),itr.next()+" Desc: "+desc.get(count));
          String itrstr = itr.next();
          rl = new RelativeLayout(this);
            titletv= new TextView(this);
            bodytv = new TextView(this);
            
            if(!itrstr.equalsIgnoreCase(titlestr)){
                
                 
                    
                    titletv.setText(Html.fromHtml(itrstr));
                    titletv.setPadding(0, 0, 0, 0);
                   bodytv.setText(Html.fromHtml(desc.get(count)));
                    titletv.setId(count);
                    bodytv.setPadding(0, 50,0, 0);
                    bodytv.setMovementMethod(new ScrollingMovementMethod());
                    rl.addView(titletv);
                    rl.addView(bodytv);
                    
                    rl.setId(2+count);
            }
            
            vf.addView(rl);
          count++;
      }
Community
  • 1
  • 1
Maverick
  • 2,738
  • 24
  • 91
  • 157

1 Answers1

1

You need to create two relative layouts (or what ever). The position in a ViewFlipper is not set through the id. It is by the time of adding them. First added -> first shown

Mark
  • 7,507
  • 12
  • 52
  • 88
  • thanks..I already implemented that. Could you tell me why i am getting a empty screen after that view? – Maverick Oct 20 '11 at 14:11
  • If I had to guess, you need to put the vf.addView(rl) inside the if. Otherwise even an empty RelativeLayout would be added. (To save ressources you should also put the creation of the new elements into it.) – Mark Oct 20 '11 at 14:17