Java 如何使用包含字符串值的微调器变量使最终结果无效

Java 如何使用包含字符串值的微调器变量使最终结果无效,java,android,Java,Android,我对微调器返回字符串值的最后一个变量有问题 请在下面的代码中显示注释,以使我的问题更清楚。 完整类别代码: 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 jav

我对微调器返回字符串值的最后一个变量有问题

请在下面的代码中显示注释,以使我的问题更清楚。 完整类别代码:

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);
              }

    }
    });









}
 }
如何使用final with spinner变量绕过空白?

更改

final Spinner spinner = new Spinner(this);

因为最终的变量与你给出的第一个实例相关联,你真的不需要做一个微调器就可以找到你想要的那个。因为您希望在方法中创建的匿名侦听器中使用微调器,所以需要final


在我看来,它永远不应该被使用,它违背了StrictMode的目的,这迫使您的代码更好一些。

如果您将其设置为类范围,则它不必是最终的。另外,StrictMode.ThreadPolicy policy=新StrictMode.ThreadPolicy.Builder.permitAll.build;这并不是你应该做什么来绕过真正有用的ScrictMode我不理解你的问题…但是如果它要求你设置修饰符final而不是声明你的微调器globally,请更具体地说明你遇到的问题。
final Spinner spinner = (Spinner) findViewById( R.id.spinner1 ); 
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();