我想使用网络服务登录。单击登录按钮时没有响应我有问题,我将loginActivity与mainActivity链接起来
包括layout="@layout/login_interface"
请帮我找出我犯的错误。请看下面的我的登录课程。
登录类
EditText editText;
EditText editText1;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_interface);
editText = (EditText) findViewById(R.id._username);
editText1 = (EditText) findViewById(R.id._passsword);
button = (Button) findViewById(R.id.singin_butt);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
login(editText.getText().toString().trim(), editText1.getText().toString().trim());
Toast.makeText(getApplication(), "Sucess11", Toast.LENGTH_LONG).show();
}
});
}
public void login(final String User_name, final String password) {
RequestQueue requestQueue = Volley.newRequestQueue(this);
String URl = KeysJason.URL_LoginUser;
StringRequest stringRequest = new StringRequest(Request.Method.POST, URl, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(response, "sss");
Toast.makeText(getApplication(), "Sucess", Toast.LENGTH_LONG).show();
startActivity(new Intent(LoginActivity_.this, ProductList.class));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(String.valueOf(error), "sss");
Toast.makeText(getApplicationContext(), "Faild", Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> parms = new HashMap<String, String>();
parms.put("username", User_name);
parms.put("password", password);
return parms;
}
};
requestQueue.add(stringRequest);
}
请查看下面的主要活动代码。
主要活动:
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
}