0

我只想在 new 时显示进度条MainActivity(detail)MainActivity(detail)用于向用户发送邮件。我所需要的只是单击按钮时,应该显示进度条并开始。然后当发送邮件时,进度条隐藏或结束。

到目前为止,这是我的代码:

OnClickListener listener=new OnClickListener()
    {   
        @Override
        public void onClick(View v)
        {
        pb=(ProgressBar)findViewById(R.id.progressBar1);
        pb.setVisibility(View.VISIBLE);

        if(isNetworkAvailable())
        {
        // TODO Auto-generated method stub
            SharedPreferences pref=getSharedPreferences("Pref", MODE_PRIVATE);
            String str=pref.getString("un1", "");
            String str1=pref.getString("pa1", "");

            SQLiteDatabase db=context.openOrCreateDatabase("IPCA", MODE_PRIVATE,null);
            Databasesignup dbs=new Databasesignup(context,"IPCA", null,1);
            dbs.onCreate(db);

            Cursor cursor=dbs.view(db,str,str1);

            ArrayList<String> al=new ArrayList<String>();
            while(cursor.moveToNext())
            {
                al.add(cursor.getString(0));
                al.add(cursor.getString(1));
                al.add(cursor.getString(5));
            }

            String string=al.get(0);
            String string1=al.get(1);
            String string2=al.get(2);
            String k=iv.getTag().toString();

            dbs.insert1(db,string,str,string2,k);

            final String detail ="\nName: "+string+"\nEmail: "+string1+"\nMobile: "+string2+"\nInterest: "+k;
            new MainActivity(detail);

            cursor.close();
            db.close();

            Toast.makeText(getApplicationContext(),"You will be contacted soon", Toast.LENGTH_LONG).show();
        }`
4

2 回答 2

2

由于您正在访问网络,因此您需要将整个操作移至后台。这是使用AsyncTask最简单的方法。然后,您可以显示您的ProgressBarinonPreExecute()并将其隐藏在onPostExecute().

于 2013-01-03T15:11:17.040 回答
0

您可以通过更改 ProgressBar 的可见性来隐藏它。

ProgressBar pBar = (ProgressBar)findViewById(R.id.your_progress_bar);
// To hide the Progress Bar set visibility to GONE.
pBar.setVisibility(View.GONE);
// To show the Progress Bar again set visibility to VISIBLE
pBar.setVisibility(View.VISIBLE);
于 2013-01-03T15:16:21.957 回答