Android 如何将微调器值获取到post窗体

Android 如何将微调器值获取到post窗体,android,string,post,spinner,Android,String,Post,Spinner,我制作了这个代码,这样我就可以将信息发送到我的网站。只是现在我想从我尝试过的微调器加载类别: String mCategory=category.getItemAtPosition(在这里放什么?).toString() 我只是不知道怎么做,我希望有人知道 net.thinkbin; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.i

我制作了这个代码,这样我就可以将信息发送到我的网站。只是现在我想从我尝试过的微调器加载类别:

String mCategory=category.getItemAtPosition(在这里放什么?).toString()

我只是不知道怎么做,我希望有人知道

net.thinkbin;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class share extends Activity {

final Context context = this;
private Button post;
private EditText title, email, author, idea, submit;
Spinner category;

@Override
protected void onCreate(Bundle savedInstanceState) {

    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.share);

    Button view = (Button) findViewById(R.id.button1);
    view.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent("net.thinkbin.TUTORIAL1"));
            overridePendingTransition(0, 0);
            finish();
        }
    });

    Button menu = (Button) findViewById(R.id.buttonhome);
    menu.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub

            // custom dialog
            final Dialog dialog = new Dialog(context);
            dialog.setContentView(R.layout.custom);

            // set the custom dialog components - text, image and button
            TextView text = (TextView) dialog.findViewById(R.id.text);
            text.setText("Loading...");
            ImageView image = (ImageView) dialog.findViewById(R.id.image);
            image.setImageResource(R.drawable.hourglass);

            dialog.show();
            Thread th = new Thread(new Runnable() {
                public void run() {

                    startActivity(new Intent("net.thinkbin.MENU"));
                    overridePendingTransition(0, 0);
                    dialog.dismiss();
                    finish();

                }
            });
            th.start();
        }
    });

    ArrayAdapter<CharSequence> adapter = ArrayAdapter
            .createFromResource(this, R.array.spinnerfood,
                    android.R.layout.simple_spinner_item);
     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    Spinner s = (Spinner) findViewById(R.id.spinner1);
    s.setAdapter(adapter);

    post = (Button) findViewById(R.id.post);
    title = (EditText) findViewById(R.id.titlefield);
    email = (EditText) findViewById(R.id.emailfield);
    author = (EditText) findViewById(R.id.authorfield);
    category = (Spinner) findViewById(R.id.spinner1);

    idea = (EditText) findViewById(R.id.ideafield);
    submit = (EditText) findViewById(R.id.submitfield);
    post.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            String mTitle = title.getText().toString();
            String mEmail = email.getText().toString();
            String mAuthor = author.getText().toString();
            String mCategory = category.getItemAtPosition().toString();
            String mIdea = idea.getText().toString();
            String mSubmit = submit.getText().toString();

            tryPost(mTitle, mEmail, mAuthor, mCategory, mIdea, mSubmit);
        }

    });
}



protected void tryPost(String mTitle, String mEmail, String mAuthor,
        String mCategory, String mIdea, String mSubmit) {
    HttpURLConnection connection;
    OutputStreamWriter request = null;

    URL url = null;
    String response = null;
    String parameters = "title=" + mTitle + "&email=" + mEmail + "&author="
            + mAuthor + "&category=" + mCategory + "&idea=" + mIdea
            + "&submit=" + mSubmit;

    try {
        url = new URL("http://www.thinkbin.net/include/api/share.php");
        connection = (HttpURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setRequestProperty("Content-Type",
                "application/x-www-form-urlencoded");
        connection.setRequestMethod("POST");

        request = new OutputStreamWriter(connection.getOutputStream());
        request.write(parameters);
        request.flush();
        request.close();
        String line = "";
        InputStreamReader isr = new InputStreamReader(
                connection.getInputStream());
        BufferedReader reader = new BufferedReader(isr);
        StringBuilder sb = new StringBuilder();
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        // Response from server after login process will be stored in
        // response variable.
        response = sb.toString();
        // You can perform UI operations here
        Toast.makeText(this, "Succes! \n" + response, 0).show();
        isr.close();
        reader.close();
        startActivity(new Intent("net.thinkbin.MENU"));
        overridePendingTransition(0, 0);
        finish();

    } catch (IOException e) {
        // Error

    }
}
}
net.thinkbin;
导入java.io.BufferedReader;
导入java.io.IOException;
导入java.io.InputStreamReader;
导入java.io.OutputStreamWriter;
导入java.net.HttpURLConnection;
导入java.net.URL;
导入android.app.Activity;
导入android.app.Dialog;
导入android.content.Context;
导入android.content.Intent;
导入android.os.Bundle;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.AdapterView.OnItemSelectedListener;
导入android.widget.ArrayAdapter;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.ImageView;
导入android.widget.Spinner;
导入android.widget.TextView;
导入android.widget.Toast;
公共类共享扩展活动{
最终上下文=此;
私人按钮柱;
私人编辑文本标题、电子邮件、作者、想法、提交;
微调器类别;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.share);
按钮视图=(按钮)findViewById(R.id.button1);
view.setOnClickListener(新的view.OnClickListener(){
公共void onClick(视图v){
//TODO自动生成的方法存根
startActivity(新意图(“net.thinkbin.TUTORIAL1”);
覆盖转换(0,0);
完成();
}
});
按钮菜单=(按钮)findViewById(R.id.buttonhome);
menu.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
//TODO自动生成的方法存根
//自定义对话框
最终对话框=新对话框(上下文);
setContentView(R.layout.custom);
//设置自定义对话框组件-文本、图像和按钮
TextView text=(TextView)dialog.findViewById(R.id.text);
text.setText(“加载…”);
ImageView image=(ImageView)dialog.findViewById(R.id.image);
setImageResource(R.drawable.hourglass);
dialog.show();
Thread th=新线程(new Runnable(){
公开募捐{
startActivity(新意图(“net.thinkbin.MENU”);
覆盖转换(0,0);
dialog.dismise();
完成();
}
});
th.start();
}
});
ArrayAdapter适配器=ArrayAdapter
.createFromResource(此,R.array.spinnerfood,
android.R.layout.simple\u微调器(项目);
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
微调器s=(微调器)findViewById(R.id.spinner1);
s、 设置适配器(适配器);
post=(按钮)findViewById(R.id.post);
title=(编辑文本)findViewById(R.id.titlefield);
email=(EditText)findViewById(R.id.emailfield);
author=(EditText)findViewById(R.id.authorfield);
类别=(喷丝器)findViewById(R.id.spinner1);
idea=(编辑文本)findViewById(R.id.ideafield);
submit=(EditText)findViewById(R.id.submitfield);
post.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
字符串mTitle=title.getText().toString();
字符串mEmail=email.getText().toString();
字符串mautor=author.getText().toString();
字符串mCategory=category.getItemAtPosition().toString();
字符串mIdea=idea.getText().toString();
字符串mSubmit=submit.getText().toString();
tryPost(mTitle、mEmail、Mautor、mCategory、美的、mSubmit);
}
});
}
受保护的void tryPost(字符串mTitle、字符串mEmail、字符串mautor、,
字符串mCategory、字符串美的、字符串mSubmit){
httpurl连接;
OutputStreamWriter请求=null;
URL=null;
字符串响应=null;
字符串参数=“title=“+mTitle+”&email=“+mEmail+”&author=”
+Mautor+“&category=“+McCategory+”&idea=“+mIdea
+“&submit=“+mSubmit;
试一试{
url=新url(“http://www.thinkbin.net/include/api/share.php");
connection=(HttpURLConnection)url.openConnection();
connection.setDoOutput(真);
connection.setRequestProperty(“内容类型”,
“application/x-www-form-urlencoded”);
connection.setRequestMethod(“POST”);
请求=新的OutputStreamWriter(connection.getOutputStream());
请求。写入(参数);
request.flush();
request.close();
字符串行=”;
InputStreamReader isr=新的InputStreamReader(
connection.getInputStream());
BufferedReader读取器=新的BufferedReader(isr);
StringBuilder sb=新的StringBuilder();
而((line=reader.readLine())!=null){
sb.追加(第+行“\n”);
}
//登录过程后服务器的响应将存储在
//响应变量。
response=sb.toString();
//您可以在此处执行UI操作
Toast.makeText(此“成功!\n”+响应,0.show();
isr.close();
reader.close();
startActivity(新意图(“net.thinkbin.MENU”);
覆盖转换(0,0);
完成();
}捕获(IOE异常){
//错误
}
}
}

有一堆
getSelected*()
。您可能需要
getSelectedItem()

这里有很多
getSelected*()
。您可能需要
getSelectedItem()