0

アプリケーションのシーク バーをカスタマイズしました。シーク バーをドラッグして、実装されていないメソッドにもアクセスできます。そして私のコードは

public class Income extends Activity implements OnSeekBarChangeListener, OnItemSelectedListener 
{ 
   SeekBar net_sales1,cogs,operating,other_revenue;
   public void onCreate(Bundle bundle)
   {
       super.onCreate(bundle);
       setContentView(R.layout.income);
       seek_txt1 = (TextView)findViewById(R.id.net_sales);
       seek_txt2 = (TextView)findViewById(R.id.cogs_te);
       seek_txt3 = (TextView)findViewById(R.id.operate_exp);
       seek_txt4 = (TextView)findViewById(R.id.other_rev);
       net_sales1 = (SeekBar)findViewById(R.id.mySeekingBar1);
       cogs = (SeekBar)findViewById(R.id.mySeekingBar2);
       operating = (SeekBar)findViewById(R.id.mySeekingBar3);
       other_revenue = (SeekBar)findViewById(R.id.mySeekingBar4);
       net_sales1.setOnSeekBarChangeListener(this);
       cogs.setOnSeekBarChangeListener(this);
       operating.setOnSeekBarChangeListener(this);
       other_revenue.setOnSeekBarChangeListener(this);
   }

   @Override
   public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
   {
       seek_count=0;
       progress1=progress-150;

       verify = fromUser;

       if (fromUser) 
       {
           if (progress >= 0 && progress <= seekBar.getMax())
           {                        

                progressString  = String.valueOf(10*progress-150);

           }
       }
       seek_id=seekBar.getId();
       switch(current_spinner)

       {
            case R.id.mySeekingBar1 :   
                //tablelay.removeView(tableLayout);


                seek_txt1.setText(progressString);
                int seekbar1_val = Integer.parseInt(seek_txt1.getText().toString());
                progress_of_spinner1 = progress;

                break;
            case R.id.mySeekingBar2 :   
                 seek_txt2.setText(progressString);
                 progress_of_spinner2 = progress;
                 break;
           case R.id.mySeekingBar3 :   
                 seek_txt3.setText(progressString);
                 progress_of_spinner3 = progress;
                 break;                                  
           case R.id.mySeekingBar4 :   
                 seek_txt4.setText(progressString);
                 progress_of_spinner4 = progress;
                 break;
         }


         net_sales1.setProgress(progress_of_spinner1);
         cogs.setProgress(progress_of_spinner2);
         operating.setProgress(progress_of_spinner3);
         other_revenue.setProgress(progress_of_spinner4);

    }
    @Override
    public void onStartTrackingTouch(SeekBar seekBar) 
    {
        int progress2 = progress1;

        originalProgress=seekBar.getProgress();

    }
    @Override
    public void onStopTrackingTouch(SeekBar seekBar) 
    {
        progress2=progress1;


    }

今私の質問は、アクティビティの onCreate() メソッド内のシーク バーのすべての実装されていないメソッドにアクセスすることは可能ですか? どんな体でも教えてもらえますか?前もって感謝します。

4

2 に答える 2

1

はい、可能です。以下のように使用します。

onSeekBarChangeListener をすべてのシーク バーに設定し、未実装のインラインの定義を提供します。以下のように:

public class Income extends Activity implements OnItemSelectedListener 
{ 
   SeekBar net_sales1,cogs,operating,other_revenue;
   public void onCreate(Bundle bundle)
   {
       super.onCreate(bundle);
       setContentView(R.layout.income);
       seek_txt1 = (TextView)findViewById(R.id.net_sales);
       seek_txt2 = (TextView)findViewById(R.id.cogs_te);
       seek_txt3 = (TextView)findViewById(R.id.operate_exp);
       seek_txt4 = (TextView)findViewById(R.id.other_rev);
       net_sales1 = (SeekBar)findViewById(R.id.mySeekingBar1);
       cogs = (SeekBar)findViewById(R.id.mySeekingBar2);
       operating = (SeekBar)findViewById(R.id.mySeekingBar3);
       other_revenue = (SeekBar)findViewById(R.id.mySeekingBar4);
       net_sales1.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
       {
           @Override
           public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
           {
                 //Do some operation in this block
           }
       });
       cogs.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
       {
           @Override
           public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
           {
                 //Do some operation in this block
           }
       });
       operating.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
       {
           @Override
           public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
           {
                 //Do some operation in this block
           }
       });// Do same as cogs
       other_revenue.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
       {
           @Override
           public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
           {
                 //Do some operation in this block
           }
       });//Do Same as cogs
   }
}

以下のように、onCreate メソッドでリスナー オブジェクトを作成し、このリスナーをすべてのシークバーに設定する別のオプション:

public class Income extends Activity implements OnItemSelectedListener 
{ 
   SeekBar net_sales1,cogs,operating,other_revenue;
   public void onCreate(Bundle bundle)
   {
       super.onCreate(bundle);
       setContentView(R.layout.income);
       seek_txt1 = (TextView)findViewById(R.id.net_sales);
       seek_txt2 = (TextView)findViewById(R.id.cogs_te);
       seek_txt3 = (TextView)findViewById(R.id.operate_exp);
       seek_txt4 = (TextView)findViewById(R.id.other_rev);
       net_sales1 = (SeekBar)findViewById(R.id.mySeekingBar1);
       cogs = (SeekBar)findViewById(R.id.mySeekingBar2);
       operating = (SeekBar)findViewById(R.id.mySeekingBar3);
       other_revenue = (SeekBar)findViewById(R.id.mySeekingBar4);
       OnSeekBarChangeListener listener= new OnSeekBarChangeListener()
       {
           @Override
           public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
           {
                 //Do some operation in this block
           }
       });
       net_sales1.setOnSeekBarChangeListener(listener);
       cogs.setOnSeekBarChangeListener(listener);
       operating.setOnSeekBarChangeListener(listener);// Do same as cogs
       other_revenue.setOnSeekBarChangeListener(listener);//Do Same as cogs
   }
}
于 2012-11-03T05:25:33.903 に答える