0

In my code I am creating some buttons dynamically based on database values.Those buttons i placed in horizontal scrollview. By pressing each button I am displaying one different page. Now my question is by dragging screen from right to left we need to display next page and that next button also will be highlight and by dragging left to right direction previous button's page should display and that button should be highlight.

my code is:

Cursor c = sqldb.rawQuery("select Diameter from ProductDetailMetric where ProductId=1", null);
            n=c.getCount();             
            arr = new String[c.getCount()];

            int i = 0;


            for (c.moveToPosition(-1); c.moveToNext(); c.isAfterLast()) {


                arr[i] = c.getString(0);
                Log.e("","no.of values----"+"--"+arr[i]);

                i++;
            }
        }
    }
    catch(Exception e){
        System.out.println(e.toString());

    }


   ll=(LinearLayout)findViewById(R.id.lll);

 for(int i=0;i<arr.length;i++){
       final Button b=new Button(this);

       b.setWidth(80);
       b.setText(arr[i]);

       ll.addView(b);

       b.setOnClickListener(new OnClickListener(){

           @Override
           public void onClick(View v) {
            // TODO Auto-generated method stub
           b.getText(); 
           Log.e("","value---"+b.getText());


           Cursor c1 = sqldb.rawQuery("select *from ProductDetailMetric where Diameter="+b.getText()+" and ProductId=1", null);
           for (c1.moveToPosition(-1); c1.moveToNext(); c1.isAfterLast()) {

           Log.e("","value---0"+c1.getString(0));
           Log.e("","value---1"+c1.getString(1));
           Log.e("","value---2"+c1.getString(2));
           Log.e("","value---3"+c1.getString(3));
           Log.e("","value--4-"+c1.getString(4));
           Log.e("","value---5"+c1.getString(5));
           e1.setText(c1.getString(8));
           e2.setText(c1.getString(9));
           e3.setText(c1.getString(10));
           e4.setText(c1.getString(11));
           e5.setText(c1.getString(12));
           e6.setText(c1.getString(13));
           e7.setText(c1.getString(14));
           e8.setText(c1.getString(15));
           e9.setText(c1.getString(16));
           e10.setText(c1.getString(17));

           }
          }
        });
 }
Padma Kumar
  • 19,893
  • 17
  • 73
  • 130

1 Answers1

0

Use a viewpager : http://developer.android.com/sdk/compatibility-library.html

Another useful link : http://viewpagerindicator.com/

Philippe Girolami
  • 1,876
  • 1
  • 13
  • 15