-1
我有一個有點問題的其他活動,我工作的一個Android應用程序,需要一個微調更新串到你的微調選擇,我擁有一切工作和一切,問題是我需要的是另一個活動上的微調,而不是啓動活動,但是當我使用與微調控件不同的活動啓動應用程序並同時激活陣列適配器和偵聽器時,我將視圖切換到具有微調員,微調員是空的,沒有選擇。我不能爲我的生活弄清楚這一點。 PS,對於我感到無聊的奇怪變量名稱感到抱歉,並且不想給出正確的名稱,而是想到現場發生的事情,然後再回來改變它。 PPS與微調框的內容視圖的名稱是orderpage,我想用app開始的是activity_main PPPS我剪掉了一些我認爲不相關的方法,所以有些變量沒有使用。我附下面我的代碼:Android的微調上比開始活動
package com.NIQUOLI.Deliveryapp;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import com.NIQUOLI.Deliveryapp.GMailSender;
import android.R.string;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Debug;
import android.os.StrictMode;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends Activity {
public static boolean deeznuts = false;
public static String storenamestring;
public static String namesame;
public static String instructionsame;
public int choice = 0;
private Spinner spinner1;
private Button button = null;
String[] stores;
Spinner sp;
public void cont(View View){
deeznuts = true;
setContentView(R.layout.orderpage);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.orderpage);
button = (Button) findViewById(R.id.send_email);
super.onCreate(savedInstanceState);
sp = (Spinner) findViewById(R.id.sp);
stores = getResources().getStringArray(R.array.stores);
if (deeznuts = true){
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,stores);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
int index = arg0.getSelectedItemPosition();
Toast.makeText(getBaseContext(), "You selected"+stores[index], Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
}
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
parent.getItemAtPosition(pos);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
當然我的XML有s [ommer:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.NIQUOLI.Deliveryapp.SendMailTask" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="@string/order_page"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="center_horizontal"
android:hint="@string/enter_your_name"
android:inputType="text" >
<requestFocus />
</EditText>
<Spinner
android:id="@+id/sp"
android:layout_width="388dp"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/instructions"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.34"
android:ems="10"
android:inputType="textMultiLine" />
<Button
android:id="@+id/send_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="@string/send_order" />
</LinearLayout>
改變了它和我的不捨它仍然是行不通的。謝謝你嘗試。 –
你永遠不會調用方法'cont',所以deeznuts永遠不會是真的,所以適配器不會在onCreate中設置。你可以改變deeznuts初始化爲真? –
哎呀,我忘了用激活微調器場景的按鈕來包含活動的XML。那個叫做cont。我的錯, –