1
任何人都可以給我完整的代碼,以獲取和發佈Android請求,例如https://wowjava.wordpress.com/2011/01/16/login-application-for-android/ 。請幫助我想從服務器進行登錄檢查。我想提出一個請求,請幫助我。作爲一個新的android
開發者我無法解決這個問題。所以請幫助我。My ArrayList <NameValuePair>正在顯示NameValuePair無法解析
的build.gradle(模塊: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'
}
我的MainActivity:
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;
}
}
'NameValuePair'已廢棄'Android的23'所以你應該使用'HashMap',而不是'NameValuePair' –
用於HTTP GET和Android的 – Imranrana07
POST請求有與HashMap的任何例子看看這裏的http: //stackoverflow.com/a/33072926/2641726 –