当我按下后退按钮(向上按钮)时,它会显示“后退”;“应用程序不幸停止”;截击后 @覆盖 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity\u导航); 但是1=(按钮)findViewById(R.id.btnlogin); // 最终字符串标记=getIntent().getExtras().getString(“标记”); //Toast.makeText(getApplicationContext(),Toast.LENGTH_SHORT.show(); 最终字符串firstName=getIntent().getExtras().getString(“firstName”); //获取cardview数据的 字符串url= com.android.volley.toolbox.JsonObjectRequest jsonRequest=新建com.android.volley.toolbox.JsonObjectRequest (Request.Method.GET,url,null,new Response.Listener()){ @凌驾 公共void onResponse(JSONObject响应){ //响应已经被构造为JSONObject! 试一试{ JSONArray obj=response.getJSONArray(“结果”); int o=对象长度(); Log.v(“长度”,String.valueOf(o)); 对于(int i=0;i
您必须为这两个键“token”、“firstname”发送字符串值 最终字符串标记=getIntent().getExtras().getString(“标记”);当我按下后退按钮(向上按钮)时,它会显示“后退”;“应用程序不幸停止”;截击后 @覆盖 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity\u导航); 但是1=(按钮)findViewById(R.id.btnlogin); // 最终字符串标记=getIntent().getExtras().getString(“标记”); //Toast.makeText(getApplicationContext(),Toast.LENGTH_SHORT.show(); 最终字符串firstName=getIntent().getExtras().getString(“firstName”); //获取cardview数据的 字符串url= com.android.volley.toolbox.JsonObjectRequest jsonRequest=新建com.android.volley.toolbox.JsonObjectRequest (Request.Method.GET,url,null,new Response.Listener()){ @凌驾 公共void onResponse(JSONObject响应){ //响应已经被构造为JSONObject! 试一试{ JSONArray obj=response.getJSONArray(“结果”); int o=对象长度(); Log.v(“长度”,String.valueOf(o)); 对于(int i=0;i,android,android-volley,Android,Android Volley,您必须为这两个键“token”、“firstname”发送字符串值 最终字符串标记=getIntent().getExtras().getString(“标记”); 最终字符串firstName=getIntent().getExtras().getString(“firstName”) 如果找不到,请在另一个类中发送意图代码片段。Punithapriya这是主要活动的代码 公共类MainActivity扩展了AppCompatActivity{ @Override protec
最终字符串firstName=getIntent().getExtras().getString(“firstName”)
如果找不到,请在另一个类中发送意图代码片段。Punithapriya这是主要活动的代码 公共类MainActivity扩展了AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation);
but1=(Button)findViewById(R.id.btnlogin);
//
final String Token=getIntent().getExtras().getString("token");
// Toast.makeText(getApplicationContext(),Token, Toast.LENGTH_SHORT).show();
final String firstName=getIntent().getExtras().getString("firstname");
//getting cardview data's
String url =
com.android.volley.toolbox.JsonObjectRequest jsonRequest = new com.android.volley.toolbox.JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// the response is already constructed as a JSONObject!
try {
JSONArray obj = response.getJSONArray("result");
int o = obj.length();
Log.v("Length", String.valueOf(o));
for (int i = 0; i < obj.length(); i++) {
JSONObject jsonObject = obj.getJSONObject(i);
//listname.add(jsonObject.getString("templateId"));
listehr.add(jsonObject.getString("templateId"));
listdate.add(jsonObject.getString("startTime"));
listtime.add(jsonObject.getString("category"));
// ehrUid.add(jsonObject.getString("ehrUid"));
List<String> compositionUid = new ArrayList<>();
// String startTime = jsonObject.getString("startTime");
// Log.v("startTime",startTime);
}
Log.v("listtime", String.valueOf(listtime.size()));
Log.v("Response", response.toString());
String total = response.getString("total");
Log.v("Total",total);
String result = response.getString("result");
Log.v("Result",result);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
System.out.println(error);
}
}){
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("Authorization",Token);
return headers;
}
};
com.android.volley.toolbox.Volley.newRequestQueue(NavigationActivity.this).add(jsonRequest);
//
TextView t;
私有文本用户名;
私有文本密码;
编辑文本显示PSD;
复选框mCbShowPwd;
公共按钮1;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//使用json登录页面
但是1=(按钮)findViewById(R.id.btnlogin);
用户名=(EditText)findViewById(R.id.editText2);
密码=(EditText)findViewById(R.id.btnpass);
但是1.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
//登录验证
if(username.getText().toString().length()=0){
username.setError(“未输入用户名”);
username.requestFocus();
}
else if(password.getText().toString().length()=0){
密码设置错误(“未输入密码”);
password.requestFocus();
}
//
字符串url=;
JsonObjectRequest jsonRequest=新的JsonObjectRequest
(Request.Method.POST,url,null,new Response.Listener()){
@凌驾
公共void onResponse(JSONObject响应){
//响应已经被构造为JSONObject!
试一试{
Log.v(“Hai”,response.toString());
String firstName=response.getString(“firstName”);
Log.v(“名字”,名字);
String organizationList=response.getString(“organizationList”);
Log.v(“组织列表”,组织列表);
String token=response.getString(“token”);
Log.v(“令牌”,令牌);
Toast.makeText(getApplicationContext(),“成功登录”,Toast.LENGTH\u SHORT.show();
意图i=新意图(MainActivity.this,NavigationActivity.class);
i、 putExtra(“令牌”,令牌);
i、 杜松子
TextView t;
private EditText username;
private EditText password;
EditText showPsd;
CheckBox mCbShowPwd;
public Button but1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//login page using json
but1=(Button)findViewById(R.id.btnlogin);
username=(EditText)findViewById(R.id.editText2);
password=(EditText)findViewById(R.id.btnpass);
but1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//validation for login
if(username.getText().toString().length()==0){
username.setError("Username not entered");
username.requestFocus();
}
else if(password.getText().toString().length()==0){
password.setError("Password not entered");
password.requestFocus();
}
//
String url = ;
JsonObjectRequest jsonRequest = new JsonObjectRequest
(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
// the response is already constructed as a JSONObject!
try {
Log.v("Hai", response.toString());
String firstName = response.getString("firstName");
Log.v("firstName", firstName);
String organizationList = response.getString("organizationList");
Log.v("organizationList",organizationList);
String token = response.getString("token");
Log.v("token",token);
Toast.makeText(getApplicationContext(),"Logged in Suceessfully", Toast.LENGTH_SHORT).show();
Intent i = new Intent(MainActivity.this,NavigationActivity.class);
i.putExtra("token",token);
i.putExtra("firstname",firstName);
startActivity(i);
finish();
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
System.out.println(error);
Toast.makeText(getApplicationContext(),"Login Error", Toast.LENGTH_SHORT).show();
}
});
Volley.newRequestQueue(MainActivity.this).add(jsonRequest);
}
});
//password
showPsd = (EditText) findViewById(R.id.btnpass);
// get the show/hide password Checkbox
mCbShowPwd = (CheckBox) findViewById(R.id.btnshow);
// add onCheckedListener on checkbox
// when user clicks on this checkbox, this is the handler.
mCbShowPwd.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// checkbox status is changed from uncheck to checked.
if (!isChecked) {
// show password
showPsd.setTransformationMethod(PasswordTransformationMethod.getInstance());
EditText et = (EditText)findViewById(R.id.btnpass);
et.setSelection(et.getText().length());
} else {
// hide password
showPsd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
EditText et = (EditText)findViewById(R.id.btnpass);
et.setSelection(et.getText().length());
}
}
});
//
//Textview calling
final TextView regLink=(TextView)findViewById(R.id.register1);
final TextView forLink=(TextView)findViewById(R.id.forgot);
//register
regLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent regIntent=new Intent(MainActivity.this,RegisterActivity.class);
MainActivity.this.startActivity(regIntent);
}
});
//forgot
forLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent forIntent=new Intent(MainActivity.this,ForgotActivity.class);
MainActivity.this.startActivity(forIntent);
}
});
}
//exit dialog box
@Override
public void onBackPressed() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("EHR Store");
builder.setIcon(R.drawable.sd);
builder.setMessage("Do you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();