我有一个标签解析错误,我一直试图解决这个错误,但一切都是徒劳的,我想将数据从一个活动移动到另一个活动,但我收到了这个错误:
------>“标签无法解析为变量”
Button ok = (Button) findViewById(R.id.ok);
ok.setOnClickListener(new View.OnClickListener() {
public void onClick (View view) {
Intent newActivity = new Intent(view.getContext(), home.class);
newActivity.putExtra("NAME", name);
startActivity(newActivity);
Log.d(TAG, name);
}
});
更新代码:
登录活动1.java
import java.util.ArrayList;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.trekeyes.android.CustomHttpClient;
public class LoginActivity1 extends Activity {
Button btnLinkToRegistrScrn;
Button loginbtn1;
Button cancelBtn;
TextView error;
EditText LgnTxt, LgnPsw;
public static DefaultHttpClient httpClient;
public static String TAG="LoginActivity1";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
LgnTxt = (EditText) findViewById(R.id.editTextLgnEmail);
LgnPsw = (EditText) findViewById(R.id.editTextLgnPassword);
error = (TextView)findViewById(R.id.login_error1);
addListenerOnButton();
// Link to Register Screen
btnLinkToRegistrScrn = (Button) findViewById(R.id.LinkToRegisterScreen);
btnLinkToRegistrScrn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
Intent i = new Intent(v.getContext(), Activity.class);
startActivity(i);
}});
// Link to Cancel Button
cancelBtn = (Button) findViewById(R.id.btnCancelLgn);
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
// Intent i = new Intent(v.getContext(), PageApp.class);
// i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(i);
}
});
}
public void addListenerOnButton() {
loginbtn1 = (Button) findViewById(R.id.btnLogin);
loginbtn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
///////// Database Handling
// TODO Auto-generated method stub
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("email", LgnTxt.getText().toString()));
postParameters.add(new BasicNameValuePair("password", LgnPsw.getText().toString()));
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://10.0.2.2/db/lgn.php", postParameters);
String res=response.toString();
res= res.replaceAll("\\s+","");
if(res.equals("1"))
{
error.setText("Correct Email And Password");
Intent intent = new Intent(arg0.getContext(), boardAct.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("EMAIL", LgnTxt.getText().toString());
startActivity(intent);
Log.d(TAG,LgnTxt.getText().toString());
finish();
}
else
error.setText("Sorry!! Incorrect Email or Password");
} catch (Exception e) {
LgnTxt.setText(e.toString());
}
}
});
}
}
boardAct.java
public class boardAct extends MapActivity {
public static String TAG="boardAct";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dashboard);
}
设置.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="1dip"
android:layout_marginTop="0dp"
android:text="@string/accountSettings"
android:textSize="25sp"
android:layout_gravity="center"
android:textStyle="bold" />
<TextView
android:id="@+id/txtlabellogSetting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="1dip"
android:layout_marginTop="6dp"
android:state_enabled="false"
android:textSize="15sp"
android:text="@string/labelsettings"
android:layout_gravity="center"
android:textStyle="bold" />
<TextView
android:id="@+id/txtboxlogSetting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="1dip"
android:layout_marginTop="6dp"
android:state_enabled="false"
android:textSize="15sp"
android:layout_gravity="center"
android:textStyle="bold" />
</LinearLayout>
设置.java
public class AccSettingsActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
addListenerOnButton();
}
private void addListenerOnButton() {
// TODO Auto-generated method stub
///////////// For TxtlogSetting ////////////
TextView logText = (TextView) findViewById(R.id.txtboxlogSetting);
String email = getIntent().getStringExtra("EMAIL");
logText.setText("email");
}