2

私はAndroidとStackoverflowを初めて使用します.Androidアプリでプログレスバーを開発することに関して助けが必要です.2つのアクティビティがあります.1番目のアクティビティから2番目のアクティビティにインテントを渡します.2つのアクティビティの間にプログレスバーを表示しようとしています. 2 番目のアクティビティの SetContentlayout の前にプログレス バーを配置することができます。これ。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);



    setContentView(R.layout.activity_sub_products);      
         Intent subprointent=getIntent();

どんな助けでも提案可能です.thankyou.

編集:ここに私の最初の活動コードがあります:

public class FrontPage extends Activity {
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_front_page);
    grid.setAdapter(new ImageAdapter(this));
     grid.setColumnWidth( 170 );
     grid.setVerticalSpacing(20 );
     grid.setStretchMode( GridView.STRETCH_COLUMN_WIDTH );
     grid.setNumColumns( GridView.AUTO_FIT );

     grid.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
             Intent subprointent=new Intent(FrontPage.this,SubProducts.class);
                startActivity(subprointent);

                  // your loading code goes here


        } 

     });



}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_front_page, menu);
    return true;
}
}

2 番目のアクティビティ コードは次のとおりです。

public class SubProducts extends Activity {
private ProgressDialog pdlg;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);



    setContentView(R.layout.activity_sub_products);      

         Intent subprointent=getIntent();


        /* if (progDailog.isShowing()) {
                progDailog.dismiss();
            }*/

        Button b1=(Button)findViewById(R.id.subbutton);


        b1.setOnClickListener(new OnClickListener() {



            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Dialog settingsDialog = new Dialog(SubProducts.this);
                settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
                settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.cust_toast_layout , null));
                settingsDialog.show();
            }

         });

}




@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_sub_products, menu);
    return true;
}
}
4

3 に答える 3

0

これが非同期タスクとプログレスバーに関する素晴らしいチュートリアルです:リンク

doInBackground中にプログレスバーを表示し、onPostExecuteでリリースする必要があります

于 2013-03-04T07:46:28.430 に答える
0

次に、レイアウトを分割することを検討する必要があります。メインレイアウトを単なるプレースホルダーとして配置します。onCreateの実行を終了し、onStart()でプログレスバーを開始して、メインアクティビティビューの子ビューのテーブルレイアウトをロードします。

activity_sub_productsのレイアウトは次のようになります

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <LinearLayout
    android:id="@+id/placeholderView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>

次に、myTableViews.xmlのようなレイアウトを作成します

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
 //put all your table views here
</LinearLayout>

次に、アクティビティのonStart()をオーバーライドして、

@Override
protected void onStart()
{
 super.onStart();
 showProgressBar("Loading...");
 LinearLayout rlView =  (LinearLayout) findViewById(R.id.placeholderView);
  rlView.addView(getLayoutInflater().inflate(R.layout.myTableViews, null));
}
    public synchronized void  showProgressBar(final String message){
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try{
                    if(pdlg == null){
                        pdlg = new ProgressDialog(MyAcitivity.this); 
                        pdlg.setCancelable(false); 
                        pdlg.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
                    }
                }catch (Exception e) {}

                try{
                    if(!pdlg.isShowing()) pdlg.show();
                    pdlg.setMessage(message); 
                }catch (Exception e) {}
            }
        });

    }

あなたは移動する必要があります

Button b1=(Button)findViewById(R.id.subbutton);


        b1.setOnClickListener(new OnClickListener() {



            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Dialog settingsDialog = new Dialog(SubProducts.this);
                settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
                settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.cust_toast_layout , null));
                settingsDialog.show();
            }

         });

onStart()の最後まで

于 2013-03-04T07:49:00.497 に答える
0

これがうまくいくことを願っています...最初のアクティビティでAsyncTaskを取得し、protected Void doInBackground(Void... params)メソッドで2番目のアクティビティ操作を実行してから、インテント、つまりstartActivity()を呼び出します。

class hello extends AsyncTask<Void,Void,Void>
{
       ProgressDialog dialog=null;
       Intent i;

   @Override
   protected void onPreExecute() 
   {


           dialog=ProgressDialog.show(MainActivity.this,"PLEASE WAIT","LOADING CONTENTS  ..",true);
   }

    @Override
    protected void onPostExecute(Void result) 
    {
            if(dialog.isShowing())
                    {
                       dialog.dismiss();

                    }           
    }

    @Override
    protected Void doInBackground(Void... params) 
    {

        // Perform your task Here and then call intent
        i = new Intent(MainActivity.this , Countries.class);
        startActivity(i);
        return null;
    }
}

ハッピーコーディング;)

于 2013-09-26T11:41:54.427 に答える