return String Value である Spinner の Final Variable に問題があります。
私のQをより明確にするために、以下のコードにコメントを表示してください。完全なクラス コード:
package com.hesham.sams;
import java.io.ByteArrayInputStream;
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.content.Intent;
//import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
//import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class ContactusActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contactus);
final TextView subjectTxt = (TextView) findViewById(R.id.subjectTxt);
final TextView emailTxtusfrom = (TextView) findViewById(R.id.emailfromTxtus);
final TextView messageTxt = (TextView) findViewById(R.id.messageTxt);
Button lButton = (Button)findViewById(R.id.sendbtn);
Typeface font = Typeface.createFromAsset(getAssets(), "extrafine.ttf");
subjectTxt.setTypeface(font);
emailTxtusfrom.setTypeface(font);
messageTxt.setTypeface(font);
String array_spinner[];
array_spinner=new String[3];
array_spinner[0]="general";
array_spinner[1]="quisiton";
array_spinner[2]="suggsution";
final Spinner spinner = new Spinner(this);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, array_spinner);
spinnerArrayAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
spinner = (Spinner) findViewById( R.id.spinner1 ); // the problem goes //here it should using final >> final spinner .. Con below >>
spinner.setAdapter(spinnerArrayAdapter);
spinner.getSelectedItem().toString();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
lButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("hesham.elnemr@gmail.com", "7323873");
}
});
;
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(emailTxtusfrom.getText().toString()));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("hesham.elnemr@gmail.com"));
message.setSubject(subjectTxt.getText().toString());
message.setContent("bfbfdbdfrt55555"+messageTxt.getText().toString() + spinner.getSelectedItem().toString(), "text/html; charset=utf-8"); // here told me that's //spinner as above should use final note : setContent take String value .
Transport.send(message);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
});
}
}
スピナー変数でファイナルを使用してボイドを回避する方法は?