Tejas
Tejas

Reputation: 358

Draw 50 button dynamically after full activity loaded

This is on create of my activity and after setting content view , I am calling LoadButton().

        @Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main);  

            Loadbuttons();
    }


     public void LoadButtonss()
       {

          Here  I am fetching data from database ,and plotting 50 buttons dynamically
       }  

So My Problem is : It is taking time in loading activity.

Any Idea how to LoadButtons() after Loading full activity. It should not wait for the ButtonLoad() function.

Any Idea how to do that?

Upvotes: 0

Views: 145

Answers (4)

Majid Daeinejad
Majid Daeinejad

Reputation: 1037

paste this code in your activity class block:

@Override
protected void onStart() {
    // TODO Auto-generated method stub
       LoadButtons();
    super.onStart();
}

Upvotes: 1

Forke
Forke

Reputation: 346

I would try this: Load buttons in onCreate and set View invisible. in onResume make it visible again.

View v;

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState); 
setContentView(R.layout.main);  

    v= findViewById(R.layout.main);
    v.setVisibility(View.INVISIBLE);

        Loadbuttons();
}


@Override
protected void onResume() {
    v.setVisibility(View.VISIBLE);
    super.onResume();
}


 public void LoadButtons()
   {
         FrameLayout layout = (FrameLayout) findViewById(R.id.MarkerLinearlayout); 
      //Here  I am fetching data from database ,and plotting 50 buttons dynamically
   }  

Upvotes: 0

loose11
loose11

Reputation: 627

You could set the buttons to invisible and if you fetch the data you can update the UI through an AsyncThread. It is not the nicest way, but it works. Otherwise use instead of Buttons a CustomListView.

Upvotes: 0

Majid Daeinejad
Majid Daeinejad

Reputation: 1037

According to the activity life cycle, you must call LoadButtons in onStart overrided method. Because activity will be visible in this state.

Upvotes: 0

Related Questions