任何人都可以为我提供完整的Http获取和发布请求的代码,例如https://wowjava.wordpress.com/2011/01/16/login-application-for-android/
。请帮助我想从服务器进行登录检查。所以我想发帖请求请帮帮我。作为一名新的android
开发人员,我无法解决这个问题。所以请帮助我。
build.gradle (module:app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.systechdigital.realtimetrackingandmonitoring"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}
我的主要活动:
package com.systechdigital.realtimetrackingandmonitoring;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.NameValuePair;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
ImageView icon_image;
ImageView login_image;
EditText username_editText;
EditText password_editText;
Button remember_me_button;
Button forget_password_button;
Button sign_up_button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
icon_image =(ImageView)findViewById(R.id.icon_imageView_id);
login_image=(ImageView)findViewById(R.id.imageView_login_id);
username_editText=(EditText)findViewById(R.id.user_login_email_id);
password_editText=(EditText)findViewById(R.id.login_password);
remember_me_button=(Button)findViewById(R.id.remember_me_id);
forget_password_button=(Button)findViewById(R.id.forget_password_id);
sign_up_button=(Button)findViewById(R.id.sign_up_button_id);
login_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent mainToSignUpIntent=new Intent(getApplicationContext(),SignUPActivity.class);
startActivity(mainToSignUpIntent);
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
}
});
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
答案 0 :(得分:0)
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
这是错误的声明,而不是NameValuePair
你假设给出arraylist
的数据类型包含
ArrayList<String> postParameters = new ArrayList<String>();