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("\n");
builder.append(value3).append("\n");
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("\n");
}
}
}
@Override
public void onClick(View V){
Toast.makeText(getApplicationContext(),getApplicationContext().getResources().getString(Integer.parseInt(result)), Toast.LENGTH_LONG).show();
}
You can append the string like this on button click
the frirst error for this line
you can't use findById in your class block you have to use it in a function like onCreate so change your code .... your code have to something like this
just remember you have to add a textView to your xml file and set this id to tv_show;
Your Main Activity Java class have somthing like this
i change Your XMl File To This iths better
I Test It every things Fine
And Show comment on Your Error there
Make
TextView
thenappend();
:in
XML
:in
Java
: