I would like to create a string whose components are appended once an ImageView is pressed.
I have an ImageView called imageView and named ImageView on clicking which I am appending a value to a string.
Finally when clicking on one button, I would like the string to show up with a Toast called out in the last Override.
I have, therefore, defined the string (named result), the button and the image, but I still get many errors, most notably I can't recall the "value1" when appending the String.
Any ideas?
Button button;
Button Click = (Button) findViewById(R.id.button);
String result;
ImageView Imageview = (ImageView) findViewById(R.id.imageView);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
(...)
public class Program {
public void main(String[] args) {
final int value1 = 300;
double value2 = 3.14;
short value3 = 5;
char value4 = 'A';
// Create StringBuilder and add four values to it.
final StringBuilder builder = new StringBuilder();
builder.append(value2).append("
");
builder.append(value3).append("
");
builder.append(value4);
// Display results.
String result = builder.toString();
System.out.println(result);
public void onClick(View v) {
Imageview.setOnClickListener(new View.OnClickListener() {
builder.append(value1).append("
");
}
}
}
@Override
public void onClick(View V){
Toast.makeText(getApplicationContext(),getApplicationContext().getResources().getString(Integer.parseInt(result)), Toast.LENGTH_LONG).show();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…