Hello all i have a button i am trying to let users share a specific sentance that has been created by three wheels that i have in my app this is the code i have so far:
private void mixWheel(int id) {
WheelView wheel = getWheel(id);
wheel.scroll(-25 + (int) (Math.random() * 50), 2000);
private String getWheelValue(int id) {
WheelView wheel = getWheel(R.id.passw_1);
int index = wheel.getCurrentItem();
((ArrayWheelAdapter<String>) wheel.getViewAdapter()).getItemText(index).toString();
String values = getWheelValue(R.id.passw_1) + " " + getWheelValue(R.id.passw_2) + " " + getWheelValue(R.id.passw_3);
return values;
Button share = (Button) findViewById(R.id.tweet);
share.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.Subject));
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.Message));
startActivity(emailIntent);
}
});
The problem is after “wheel.scroll(-25 + (int) (Math.random() * 50), 2000);”
I get this error “Syntax error, insert “}” to complete MethodBody”
If i put it after that line of code i then get an error under
“Button share = (Button) findViewById(R.id.tweet);”
Saying: Unreachable code
With qucik fix “Remove” but this just removes everything after that line of code i have posted the full code below just incase. Thanks in advance.
public class PasswActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.passw_layout);
initWheel(R.id.passw_1, new String[] { "You", "Me", "Us" });
initWheel(R.id.passw_2, new String[] { "Are", "Going", ""Went });
initWheel(R.id.passw_3, new String[] { "There", "Here", ""Away });
Button mix = (Button) findViewById(R.id.btn_mix);
mix.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mixWheel(R.id.passw_1);
mixWheel(R.id.passw_2);
mixWheel(R.id.passw_3);
}
});
}
// Wheel scrolled flag
private boolean wheelScrolled = false;
// Wheel scrolled listener
OnWheelScrollListener scrolledListener = new OnWheelScrollListener() {
public void onScrollingStarted(WheelView wheel) {
wheelScrolled = true;
}
public void onScrollingFinished(WheelView wheel) {
wheelScrolled = false;
}
};
// Wheel changed listener
private OnWheelChangedListener changedListener = new OnWheelChangedListener() {
public void onChanged(WheelView wheel, int oldValue, int newValue) {
if (!wheelScrolled) {
}
}
};
/**
* Initializes wheel
*
* @param id
* the wheel widget Id
*/
private void initWheel(int id, String[] values) {
WheelView wheel = getWheel(id);
wheel.setViewAdapter(new ArrayWheelAdapter<String>(this, values));
wheel.setCurrentItem((int) (Math.random() * 10));
wheel.addChangingListener(changedListener);
wheel.addScrollingListener(scrolledListener);
wheel.setCyclic(true);
wheel.setInterpolator(new AnticipateOvershootInterpolator());
}
/**
* Returns wheel by Id
*
* @param id
* the wheel Id
* @return the wheel with passed Id
*/
private WheelView getWheel(int id) {
return (WheelView) findViewById(id);
}
/**
* Tests entered PIN
*
* @param v1
* @param v2
* @param v3
* @param v4
* @return true
*/
private boolean testPin(int v1, int v2, int v3, int v4) {
return testWheelValue(R.id.passw_1, v1)
&& testWheelValue(R.id.passw_2, v2)
&& testWheelValue(R.id.passw_3, v3);
}
/**
* Tests wheel value
*
* @param id
* the wheel Id
* @param value
* the value to test
* @return true if wheel value is equal to passed value
*/
private boolean testWheelValue(int id, int value) {
return getWheel(id).getCurrentItem() == value;
}
/**
* Mixes wheel
*
* @param id
* the wheel id
*/
private void mixWheel(int id) {
WheelView wheel = getWheel(id);
wheel.scroll(-25 + (int) (Math.random() * 50), 2000);
private String getWheelValue(int id) {
WheelView wheel = getWheel(R.id.passw_1);
int index = wheel.getCurrentItem();
((ArrayWheelAdapter<String>) wheel.getViewAdapter()).getItemText(index).toString();
String values = getWheelValue(R.id.passw_1) + " " + getWheelValue(R.id.passw_2) + " " + getWheelValue(R.id.passw_3);
return values;
Button share = (Button) findViewById(R.id.tweet);
share.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.Subject));
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.Message));
startActivity(emailIntent);
}
});
}
}
Why is your getWheelValue() method inside of mixWheel? Try moving it outside of mixWheel like so, and re-organize your calls
I’m not even sure if that is valid syntax (a method within a method) – someone correct me if I am wrong.