-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
126 lines (110 loc) · 4.67 KB
/
MainActivity.java
File metadata and controls
126 lines (110 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.example.firstquestion;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
Spinner sp;
boolean invalid = false;
String Colector="";
TextView txtalertName;
EditText UserName,UserPassword,UserContact,UserComment;
Button SubmitSave;
RadioButton Malebtn,Femalbtn;
CheckBox html,css,php;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp=findViewById(R.id.SpCountry);
UserName=findViewById(R.id.userName);
UserPassword=findViewById(R.id.userPassword);
UserContact=findViewById(R.id.userContact);
UserComment=findViewById(R.id.usercomment);
txtalertName=findViewById(R.id.userAlert);
Malebtn =findViewById(R.id.Male);
Femalbtn=findViewById(R.id.Female);
html=findViewById(R.id.HTML);
css=findViewById(R.id.CSS);
php=findViewById(R.id.PHP);
SubmitSave=findViewById(R.id.btnSubmit);
SubmitSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = UserName.getText().toString();
String Pascode=UserPassword.getText().toString();
String contact=UserContact.getText().toString();
String comment=UserComment.getText().toString();
if (name.isEmpty()){
Toast.makeText(MainActivity.this,"Pleas fill the password field",Toast.LENGTH_SHORT).show();
}
else if (name.equals("Sameh") ||name.equals("UlHaq")){
invalid=true;
txtalertName.setText("Name Already exist");
}
else if(Pascode.isEmpty()){
Toast.makeText(MainActivity.this,"Pleas fill the password field",Toast.LENGTH_SHORT).show();
}
else if (contact.isEmpty()){
Toast.makeText(MainActivity.this,"Pleas fill the Contact field",Toast.LENGTH_SHORT).show();
}
else if (comment.isEmpty()){
Toast.makeText(MainActivity.this,"Pleas fill the Comment field",Toast.LENGTH_SHORT).show();
}
else{
Colector+=name+"\n";
Colector+=Pascode+"\n";
Colector+=contact+"\n";
Colector+=comment+"\n";
if (html.isChecked()){
Colector+="HTML"+"\n";
if (css.isChecked()){
Colector+="CSS"+"\n";
}
if (php.isChecked()){
Colector+="PHP"+"\n";
}
}
Toast.makeText(MainActivity.this,"User Info \n:"+Colector,Toast.LENGTH_SHORT).show();
}
}
});
List<String> categoryCountry=new ArrayList<>();
categoryCountry.add("Select Country");
categoryCountry.add("PAKISTAN");
categoryCountry.add("AFGHANISTAN");
categoryCountry.add("UAE");
categoryCountry.add("TURKEY");
categoryCountry.add("AMERICA");
ArrayAdapter<String> arrayAdapter;
arrayAdapter=new ArrayAdapter<>(this,android.R.layout.simple_spinner_item,categoryCountry);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp.setAdapter(arrayAdapter);
sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long l) {
if(parent.getItemAtPosition(position).equals("Select Country")){
//Do Nothing
}
else{
String item=parent.getItemAtPosition(position).toString();
Colector+=item+"\n";
Toast.makeText(MainActivity.this, "Selected Country: "+item, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
}