StackReject
Lurker
I am a self taught new android/java developer and know just enough to realize i don't know nearly enough. Where should i look make my code more efficient ?
Below is an app I'm writing that utilizes a couple hundred seekbars and multiple activities.
Each seekbar generated global Integers and passes them through intent to the secons activity.
Am I going to have to stay this course 100 times per activity?
Is there a more intelligent approach?
*
Below is an app I'm writing that utilizes a couple hundred seekbars and multiple activities.
Each seekbar generated global Integers and passes them through intent to the secons activity.
Am I going to have to stay this course 100 times per activity?
Is there a more intelligent approach?
*
Code:
*
public class MainActivity extends Activity
{
public SeekBar bar;
TextView value;
public SeekBar bar2;
TextView value2;
TextView value3;
int A2;
int B2;
int C2= A2+B2;
//#3
public SeekBar bar3;
TextView value31;
public SeekBar bar32;
TextView value32;
TextView value33;
int A3;
int B3;
int C3= A3+B3;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Right Contact (2)
value = (TextView) findViewById(R.id.textview);
bar = (SeekBar) findViewById(R.id.seekbar);
//Left Contact (2)
value2 = (TextView) findViewById(R.id.textview2);
bar2 = (SeekBar) findViewById(R.id.seekbar2);
//total (2)
value3 = (TextView) findViewById(R.id.textView4);
//#3
//Right Contact (2)
value31 = (TextView) findViewById(R.id.textview3);
bar3 = (SeekBar) findViewById(R.id.seekbar3);
//Left Contact (2)
value32 = (TextView) findViewById(R.id.textview31);
bar32 = (SeekBar) findViewById(R.id.seekbar31);
//total (2)
value33 = (TextView) findViewById(R.id.textView32);
// Right Contact SeekBar (2)
bar.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
{
{
// TODO Auto-generated method stub
A2= progress;
value.setText("Left Contact:"+A2);
value3.setText("Delta:"+ (A2+B2));
C2 = A2+B2;
}
// TODO Auto-generated method stub
}
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
});
// Left Contact SeekBar (2)
bar2.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar seekBar, int progress1,boolean fromUser)
{
{
// TODO Auto-generated method stub
B2 = progress1 ;
value2.setText("Right Contact:"+B2);
value3.setText("Delta:"+ (A2+B2));
C2 = A2+B2;
}
}
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
});
//#3
// Right Contact SeekBar (3)
bar3.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser)
{
{
// TODO Auto-generated method stub
A3= progress;
value31.setText("Left Contact:"+A3);
value33.setText("Delta:"+ (A3+B3));
C3 = A3+B3;
}
//TODO Auto-generated method stub
}
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
});
// Left Contact SeekBar (3)
bar32.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar seekBar, int progress1,boolean fromUser)
{
{
// TODO Auto-generated method stub
B3 = progress1 ;
value32.setText("Right Contact:"+B3);
value33.setText("Delta:"+ (A3+B3));
C3 = A3+B3;
}
}
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
});
//Button switch between activities
Button btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent myIntent = new Intent(MainActivity.this, Graph1Activity.class);
myIntent.putExtra("Right",value.getText().toString());
myIntent.putExtra("Left",value2.getText().toString());
myIntent.putExtra("CC2",value3.getText().toString());
myIntent.putExtra("C2",C2);
//(3)
myIntent.putExtra("Right3",value31.getText().toString());
myIntent.putExtra("Left3",value32.getText().toString());
myIntent.putExtra("CC3",value33.getText().toString());
myIntent.putExtra("C3",C3);
MainActivity.this.startActivity(myIntent);
}
});
Second Activity
public class Graph1Activity extends Activity {
int C2;
int C3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.graph1);
Bundle extras = getIntent().getExtras();
int C2 = extras.getInt("C2");
//total (2)
TextView tvtvtv = (TextView) findViewById(R.id.textView1);
tvtvtv.setText(""+getIntent().getExtras().getString("CC2"));
//(2)
TextView tv = (TextView) findViewById(R.id.textView2);
tv.setText(""+getIntent().getExtras().getString("Right"));
//(2)
TextView tvtv = (TextView) findViewById(R.id.textView3);
tvtv.setText(""+getIntent().getExtras().getString("Left"));
int C3 = extras.getInt("C3");
//total (3)
TextView tvtvtv3 = (TextView) findViewById(R.id.textView31);
tvtvtv3.setText(""+getIntent().getExtras().getString("CC3"));
//(3)
TextView tv3 = (TextView) findViewById(R.id.textView32);
tv3.setText(""+getIntent().getExtras().getString("Right3"));
//(3)
TextView tvtv3 = (TextView) findViewById(R.id.textView33);
tvtv3.setText(""+getIntent().getExtras().getString("Left3"));
//Button switch between activities
Button btn=(Button)findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent myIntent = new Intent(Graph1Activity.this, MainActivity.class);
int intValue = myIntent.getIntExtra("value3", 0);
int intValue3 = myIntent.getIntExtra("value33", 0);
Graph1Activity.this.startActivity(myIntent);
}
});
GraphViewSeries exampleSeries = new GraphViewSeries(new GraphViewData[] {
new GraphViewData(1, 2.0d)
, new GraphViewData(2, C2)
, new GraphViewData(3, C3)
, new GraphViewData(4, 2.0d)
,new GraphViewData(5, 2.0d)
, new GraphViewData(6, 2.0d)
, new GraphViewData(7, 2.0d)
, new GraphViewData(8, 2.0d)
,new GraphViewData(9, 2.0d)
, new GraphViewData(10,2.0d)
, new GraphViewData(11, 2.0d)
, new GraphViewData(12, 2.0d)
,new GraphViewData(13, 2.0d)
, new GraphViewData(14, 2.0d)
, new GraphViewData(15, 2.0d)
, new GraphViewData(16, 2.0d)
,new GraphViewData(17, 2.0d)
, new GraphViewData(18, 2.0d)
, new GraphViewData(19, 2.0d)
, new GraphViewData(20, 2.0d)
,new GraphViewData(21, 2.0d)
, new GraphViewData(22, 2.0d)
, new GraphViewData(23, 2.0d)
, new GraphViewData(24, 2.0d)
, new GraphViewData(25, 2.0d)
, new GraphViewData(26, 2.0d)
, new GraphViewData(27, 2.0d)
,new GraphViewData(28, 2.0d)
, new GraphViewData(29, 2.0d)
, new GraphViewData(30, 2.0d)
, new GraphViewData(31, 2.0d)
,new GraphViewData(32, 2.0d)
, new GraphViewData(33, 2.0d)
, new GraphViewData(34, 2.0d)
, new GraphViewData(35, 2.0d)
,new GraphViewData(36, 2.0d)
, new GraphViewData(37, 2.0d)
, new GraphViewData(38, 2.0d)
, new GraphViewData(39, 2.0d)
,new GraphViewData(40, 2.0d)
, new GraphViewData(41, 2.0d)
, new GraphViewData(42, 2.0d)
, new GraphViewData(43, 2.0d)
,new GraphViewData(44, 2.0d)
, new GraphViewData(45, 2.0d)
, new GraphViewData(46, 2.0d)
, new GraphViewData(47, 2.0d)
, new GraphViewData(48, 2.0d)
, new GraphViewData(49, 2.0d)
, new GraphViewData(50, 2.0d)
,new GraphViewData(51, 2.0d)
, new GraphViewData(52, 2.5d)
, new GraphViewData(53, 2.5d)