package walmart.namespace;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class WalmartActivity extends Activity {
/** Called when the activity is first created. */
EditText name;
Button search;
TextView display;
@Override
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.main);
super.onCreate(savedInstanceState);
name = (EditText)findViewById(R.id.etName);
search = (Button) findViewById(R.id.btnSearch);
display = (TextView) findViewById(R.id.tvdisplay);
name.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
name.setText("");
}
});
search.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (name.equals("Electronics")) {
display.setText ('5');
} else if (name.equals("candy")) {
display.setText ('1');
} else if (name.equals("Tobacco")) {
display.setText ("1");
}
}});
};}
No matter what i do, nothing shows up in my output. I’m very, very new to JAVA, so I can’t seem to find out why nothing’s showing up on my display.
edit Edited my code to what i currently have. Still not working.
Looking at that code, the issue might be with how you are initializing name and search.
Change your code:
to this:
Also, add a TextView to display your answer into your
main.xmlfile, give it an id (let’s say display for example)android:id="@+id/display"and then add it to your activity so you can change it:and then you can update it by calling:
Thus the start of your file should look like this:
Next update your
ifstatements from:to:
An example piece of code:
Demo2Activity.java
main2.xml