Can't change activity in my App using PlainText as login - android-studio

I am a noob developer in android who is just learning to experiment with activities and stuff like that. Today I learnt about TextFields, and tried to use a normal plaintext EditText view as a username, a password-input type EditText view, and a button to which an onClick method by the name of "loginMethod" was attached. I used simple if-else statements by taking the inputs in the text fields to string and want to open a new activity when the desired username and password are entered, and to show a toast if not. However, on running the application it only gives the toast message for the error and doesn't start the activity.
The code for the method is attached below:
public void loginMethod(View view)
{
EditText username=(EditText) findViewById(R.id.username);
EditText password=(EditText) findViewById(R.id.password);
String user_name=username.getText().toString();
String pass_word=password.getText().toString();
Log.i("Info","Entered username: "+user_name+" and Entered password: "+pass_word);
Context context=getApplicationContext();
int duration= Toast.LENGTH_LONG;
if (user_name=="myuser" && pass_word == "mypass")
{
Intent i=new Intent(MainActivity.this,welcome.class);
startActivity(i);
}
else Toast.makeText(getApplicationContext(),"Wrong Username or Password!",duration).show();
}
The output when the image is run is also attached in the image below. Please help.
Check out the output screenshot from here

Change this line:
if (user_name.text.toString()=="myuser" && pass_word.text.toString() == "mypass")

Related

Trying to write test case in Cucumber where I use one or more pieces of data

I'm trying to write out a test case where the input could be one or more items.
Example:
Scenario: Changes to a user's address in the system are saved to the database
Feature: Make a change to one or more of a user's address fields.
Given I'm logged into the system.
When I make a change to <field>.
And Click Save.
Then Changes are saved into database.
|Field|
|Street Address|
|City|
|State|
|ZIP Code|
This scenario works if its only one field I'm changing, ex. ZIP Code.
But how do I write it for scenarios where I want to change multiple items?
Example, change City and State or City, State, and ZIP code.
You need a Scenario Outline rather than a scenario alone. This is how you create a scenario outline:
Feature: Make a change to one or more of a user's address fields.
Scenario Outline: Changes to a user's address in the system are saved to the database
Given I'm logged into the system.
When I make a change to <Field>.
And Click Save.
Then Changes are saved into database.
Examples:
|Field|
|Street Address|
|City|
|State|
|ZIP Code|
A scenario outline is easily identified by the key phrase Scenario Outline. The purpose of a scenario outline is to loop through a test case with different input parameters. These input parameters are included in a data table underneath a section labeled "Examples". Lastly, the label of the table header must match a parameter used in one or more test steps, enclosed in angular brackets <>.
There are two ways you can do that
1. simple scenario outline. (fields are horizontal)
Scenario Outline: login registration
When I submit login details <Username> <Password> <UsernameDesc>
Examples:
|Username|Password|UsernameDesc|
|"uname1" |"password"|"testuserName1"|
|"uname2" |"password"|"testuserName2"|
step def for above method is
#When("I submit login details {string} {string} {string}")
public void register(String usrname, String pwd, String desc){
// use usrname, pwd, desc as desired
}
2. using data table (#DatatableType). (fields are vertical)
Scenario: login registration using cucumber data table
When I submit login details
|Username |"username"|"username1"|"username2"|
|Password |"password"|"password1"|"password2"|
|UsernameDesc |"testDesc"|"testDesc1"| "password2"|
step defs for above method
#DataTableType
public loginDetails logindetails(Map<String, String> entry) {
return new loginDetails(entry.get("Username"),entry.get("Password"),entry.get("UsernameDesc"));
}
#When ("^I submit login details$")
public void submitLoginDetails(DataTable dataTable ){
List<loginDetails> list = dataTable.transpose().asList(loginDetails.class);
list.stream().forEach(System.out::println);
for (loginDetails l : list) {
System.out.println("username::"+l.getUserName());
System.out.println("pwd::"+l.getPassword());
System.out.println("usernamedesc::"+l.getUsernameDesc());
}
}
pojo class used in above method is like this
public class loginDetails {
private String Username;
private String Password;
private String UsernameDesc;
public loginDetails(String uname, String pwd, String udesc){
this.Username=uname;
this.Password = pwd;
this.UsernameDesc = udesc;
}
public String getUserName() {
return Username;
}
public String getPassword() {
return Password;
}
public String getUsernameDesc() {
return UsernameDesc;
}
}

How do I clear the input of a Smart Panel dialog (PXFilter)?

I have created a smart panel in a custom screen to ask for user input that is used to facilitate moving stock from normal inventory into an isolation area. My original smart panel example that I always use is the Copy Order in the SOOrderEntry graph (SO301000). In this case, I need to do a bit of validation, and the user may very well decide to close the smart panel and update the document in the screen before reopening the smart panel again. If the user clicks the cancel button, I need the smart panel to reset back to defaults every time it is opened.
I thought this might be handled in the ASPX screen definition, but I can't find the right setting for the form itself. I use AutoRefresh on selectors to refresh every time they are opened, but I need the form itself to do the same and refresh back to default every time it is opened. The desired behavior DOES occur automatically when I navigate to another record of the graph's primary DAC, but I cannot seem to force the smart panel to refresh automatically every time it is opened. I looked at the various options for the form in ASPX, but I overlooked it if it is there.
Similarly to CopyOrder on SOOrderEntry, here is my code sample from my graph.
public PXFilter<StockParamFilter> stockparamfilter;
#region AddFromStock
public PXAction<MyTag> addFromStock;
[PXUIField(DisplayName = Messages.AddFromStock, MapEnableRights = PXCacheRights.Insert, MapViewRights = PXCacheRights.Insert)]
[PXButton]
protected virtual IEnumerable AddFromStock(PXAdapter adapter)
{
MyTag tag = Tags.Current;
if (tag?.TranRefNbr != null)
{
throw new PXException(Messages.TagAlreadyReceived);
}
MyTagEntry graph = PXGraph.CreateInstance<MyTagEntry>();
WebDialogResult dialogResult = stockparamfilter.AskExt(setStockStateFilter, true);
if (dialogResult == WebDialogResult.OK || (IsContractBasedAPI && dialogResult == WebDialogResult.Yes))
{
// My Business Logic Here
}
return adapter.Get();
}
#endregion
#region CheckStockParams (OK Button in Smart Panel)
public PXAction<MyTag> checkStockParams;
[PXUIField(DisplayName = "OK", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
[PXLookupButton]
public virtual IEnumerable CheckStockParams(PXAdapter adapter)
{
return adapter.Get();
}
#endregion
#region setStockStateFilter
private void setStockStateFilter(PXGraph aGraph, string ViewName)
{
checkStockStateFilter();
}
#endregion
#region checkStockStateFilter
protected virtual void checkStockStateFilter()
{
// My Business Logic Here to set bool enableStockParams = ???
checkStockParams.SetEnabled(enableStockParams);
}
#endregion
This seems like something I did in the past, but I cannot seem to locate the code. I think it is related to stockparamfilter being a PXFilter instead of a PXSelect (or SelectFrom).
I have tried stockparamfilter.ClearDialog() with no luck. I have tried stockparamfilter.RequestRefresh() with no luck. I even tried stockparamfilter.DeleteCurrent() which seemed to work when I hit Cancel, but then my code did not execute when I hit OK. I also seemed to get the desired results when I used stockparamfilter.Cache.SetDefaultExt<StockParamFilter.locationID>(filter); on every field, until I hit OK which did nothing. It's like every time I try to manipulate the filter, I break the smart panel without any errors in the trace. In fact, here is the list of what I tried unsuccessfully:
StockParamFilter filter = stockparamfilter.Current;
stockparamfilter.View.Clear();
stockparamfilter.View.RequestRefresh();
stockparamfilter.Cache.Clear();
stockparamfilter.View.RequestRefresh();
stockparamfilter.View.RequestFiltersReset();
stockparamfilter.DeleteCurrent();
stockparamfilter.ClearDialog();
stockparamfilter.Cache.SetDefaultExt<StockParamFilter.locationID>(filter);
stockparamfilter.Cache.SetDefaultExt<StockParamFilter.toLocationID>(filter);
stockparamfilter.Cache.SetDefaultExt<StockParamFilter.qty>(filter);
stockparamfilter.Cache.SetDefaultExt<StockParamFilter.lotSerialNbr>(filter);
stockparamfilter.Cache.SetDefaultExt<StockParamFilter.origRefNbr>(filter);
What is the ASPX code or C# Code that will let me reset the smart panel to defaults?
A big thanks to Hughes Beausejour at Acumatica for the offline assist. Posting solution for anyone else that may have this issue.
First, it is important to understand that AskExt generates 2 passes of the code. The first pass prompts the smart panel. Upon response to the smart panel, the code executes again, but in this second context skips the ask. With that in mind, the reason for my code not working became clear, as Hughes explained to me.
To execute the code when the form is initialized, that code must be executed before the ask occurs. Otherwise, the form is presented and then the initializing code is executed too late. Additionally, it must be conditioned such that it only fires when the smart panel was not given an OK response by the user. (Not realizing the code executes twice, I was unaware that I was resetting the fields on both passes. When I could get the form to reset, the subsequent processing would fail becuase I was resetting it on that pass as well.) Following that code, the AskExt can be used to present the form along with the normal processing of the user response.
My code, to show the working example, is as follows:
StockParamFilter filter = stockparamfilter.Current;
// If the user response is anything except an affirmative, default the fields
if (!(stockparamfilter.View.Answer == WebDialogResult.OK || (IsContractBasedAPI && stockparamfilter.View.Answer == WebDialogResult.Yes)))
{
stockparamfilter.Cache.SetDefaultExt<StockParamFilter.locationID>(filter);
stockparamfilter.Cache.SetDefaultExt<StockParamFilter.toLocationID>(filter);
stockparamfilter.Cache.SetDefaultExt<StockParamFilter.qty>(filter);
stockparamfilter.Cache.SetDefaultExt<StockParamFilter.lotSerialNbr>(filter);
stockparamfilter.Cache.SetDefaultExt<StockParamFilter.origRefNbr>(filter);
}
// Present the Smart Panel Dialog (happens only on the 1st pass - AskExt causes the code to execute twice)
WebDialogResult dialogResult = stockparamfilter.AskExt(setStockStateFilter, true);
// If the response was affirmative, execute the business logic
if (dialogResult == WebDialogResult.OK || (IsContractBasedAPI && dialogResult == WebDialogResult.Yes))
{
// Do Business Logic Based On User Response In Smart Panel
}

android studio kotlin save choice into temporary arraylist then access temporary arraylist

im new to android studio.
can someone please give me an example how to save the choices to temporary arraylist, then choose again from the temporary arraylist?
for example, there are 2 images to choose from on either side of the screen. once i choose either one, that image is saved into temp arraylist.
However, when i run this, it gives me null pointer exception where i am trying to access temp array.
my guess is because they are in oncreate method. how can i resolve the issue?
Thank you!!
var list = mutableListOf(R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4)
var temp: MutableList<Int> = ArrayList()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.game)
imageView1.setImageResource(list[0])
imageView2.setImageResource(list[1])
imageView1.setOnClickListener{
temp.add(list[0])
}
imageView2.setOnClickListener{
temp.add(list[0])
}
imageView1.setImageResource(list[2])
imageView2.setImageResource(list[3])
imageView1.setOnClickListener{
temp.add(list[1])
}
imageView2.setOnClickListener{
temp.add(list[1])
}
imageView1.setImageResource(temp[0]) // error here
imageView2.setImageResource(temp[1])
imageView1.setOnClickListener{
textView.setText("Right Won")
}
imageView2.setOnClickListener{
textView.setText("Left Won")
}
}
When your Activity is created it runs that code, from top to bottom. You set click listeners which will add items to temp when the user clicks them, but that can't happen until after onCreate has finished running.
So when you get to the line with the error, a few nanoseconds later, you're trying to access the contents of temp but it's empty, right?
All your code at bottom looks like it should be run in response to the user clicking on something, not when the Activity is first created. You should put it in a separate function, called something like checkResult and call that from your click listeners, to check the result after the user clicks something!

how to get a value from a edit control using coded UI test

I am trying to get an Order number from a text field using coded UI TEST
The text field id is : order_no.
I know with selenium i would use:
String strOrderNumber=driver.findElement(By.id("order_no")).getAttribute("value");
My code in codedUi test
public static void getOrderNumber(UITestControl Control)
{
Control.TechnologyName = "web"; Control.SearchProperties.Add("Controltype", "Edit");
Control.SearchProperties.Add("Id", "order_no");
OrderNumber = Control.GetProperty("Text").ToString();
Console.Write(OrderNumber);
}
enter image description here

Using a Textfield to switch to a displayable in Java Me

I'm working with java me, I built an app using forms displayables. I'm trying to switch to other forms, based on the user's input in a textfield item. For example, I want the user to be able to type in the number "1" in the textfield and then be taken to form1 or type in "2" and be taken to form2 etc.
What's the code to do this?
Here's what I did but it's not working as expected:
form.setItemStateListener(new ItemStateListener() {
public void itemStateChanged(Item item) {
if (item == TextField) {
if ("1".equals(TextField.getString())) {
switchDisplayable(null, form1);
}
}
}
I've done as adviced. I added a command to the textfield item and listen on it to read textfield contents and then compare the contents as a string, to switch forms. See my code below, still not working. I think maybe there's something I'm missing or my logic is not right.
form.setCommandListener(new CommandListener() {
public void commandAction(Command command, Displayable displayable) {
if (command == getTextFieldItemCommand()) {
if ("1".equals(TextField.getString())) {
switchDisplayable(null, form1);
} else if ("2".equals(TextField.getString())){
switchDisplayable(null, form2);
}
}
}
It looks like you expect method itemStateChanged to be invoked when it feels convenient to you, like at every character entry in the text field.
Above expectation is wrong, specified behavior is explained in API javadocs:
It is up to the device to decide when it considers a new value to have been entered into an Item... In general, it is not expected that the listener will be called after every change is made...
Given above, using itemStateChanged the way you want makes very little sense, consider changing design of your MIDlet.
I for one would probably just add a command Go and command listener to the form or text field and read text field contents when user invokes that command to find out which displayable they want to switch to.

Resources