开发者

How to get elements from array list in android

Hi all in my application by using web service i get the data from database and stored that data in hash table.I took that data from hast table to array.this array data can be displayed in button.My array contains 10 elements.For animation i used view flipper.Now i want to do is display that array elements on button one after another for every 10sec.But in Updater method i didn't get all array elements.How to solve this one

i am sending my code //in on create method i wore this one

user_advertise is the hash table

                     System.out.println(""+user_advertise.size());
             array=new String[user_advertise.size()];

            e= user_advertise.keys();

            int i = 0;
            int j=0;
            for(i=user_advertise.size();;i++){
            array[j]=e.nextElement().toString();


            LinearLayout layout = (LinearLayout) findViewById(R.id.LinearLayout01); 

            LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( 
                                LinearLayout.LayoutParams.FILL_PARENT, 
                                LinearLayout.LayoutParams.WRAP_CONTENT 
                        ); 


            Button buttonView = new Button(this); 
             buttonView.setText("" +array[i]);


            Timer timing = new Timer();
            timing.schedule(new Updater(buttonView), 3000, 3000);

             ViewFlipper flipper = new ViewFlipper (this); 
             flipper.addView(buttonView);
             layout.addView(flipper,p);
             flipper.startFlipping();
             flipper.setClickable(true);
             flipper.setFlipInterval(10000);
             flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_in));
             flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.push_left_out));


            } 

            }catch(Exception e)
            {
                Log.v("Add",e.toString());

            } 

   }
private class Updater extends TimerTask {
    private final Button buttonView;

    public Updater(Button buttonView) {
        this.buttonView = buttonView;
    }

    public void run() {
        buttonView.post(new Runnable() {


            public void run() {

                int k=0;

                    buttonView.setText(" ");

                    buttonView.setText(""+ar开发者_如何学运维ray[k].toString()+"");

                if(array[++k]!= null)
                {
                    k++;
                }

            } 


You have defined and initialized int k=0; within the thread block so everytime it will run, k will always be 0 so you will have to define it outside.

Also

if(array[++k]!= null)
{
   k++;
}

will increment k twice : one for the if test and one in the block

What you want is:

if(k != array.length - 1) k++;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜