Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在我的android应用程序中创建自定义微调器_Java_Android_Android Layout_Spinner_Android Spinner - Fatal编程技术网

Java 在我的android应用程序中创建自定义微调器

Java 在我的android应用程序中创建自定义微调器,java,android,android-layout,spinner,android-spinner,Java,Android,Android Layout,Spinner,Android Spinner,嗨,我想在我的android应用程序中创建一个自定义的微调器。但我无法发展这一点。请帮帮我 这是我的xml代码: main.xml <?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fil

嗨,我想在我的android应用程序中创建一个自定义的
微调器。但我无法发展这一点。请帮帮我

这是我的xml代码:

main.xml

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
 android:background="#ffffffff" >



 <TextView
    android:id="@+id/textView9"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="50dp"
    android:layout_y="110dp"
    android:text="Status"
    android:textSize="20dip"
   android:textColor="#1d2328"
   />

  <Spinner android:id="@+id/spinner1" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="150dp"
    android:layout_y="100dp" android:prompt="@string/status_prompt"
    android:background="@drawable/btn_dropdown"
      />

  <Button
    android:id="@+id/btn_insert1"
    android:layout_width="250dp"
    android:layout_height="40dp"
    android:layout_y="170dp"
    android:layout_x="35dp"
    android:background="@drawable/lgnbttn"
   android:textColor="#FFFFFF"
    android:text="Update" />


     <TextView
    android:id="@+id/textView2"
    android:layout_width="280dp"
    android:layout_height="43dp"

    android:layout_x="20dp"
    android:layout_y="255dp"
   android:textColor="#465371"
    android:gravity="center"
    android:textAppearance="?android:attr/textAppearanceMedium" />

  </AbsoluteLayout>

这是我的java代码:

public class InsertionExample extends Activity {
private final String NAMESPACE = "http://xcart.com";
private final String URL = "http://192.168.1.168:8089/XcartLogin/services/update?wsdl";
private final String SOAP_ACTION = "http://xcart.com/insertData";
private final String METHOD_NAME = "insertData";
Button btninsert;
String selectedItem;
private int i;

static final String KEY_NAME = "orderid";
static final String KEY_STATUS = "status";
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.change_status);
    if (customTitleSupported) {
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
    }

    final TextView myTitleText = (TextView) findViewById(R.id.mytitle);
    if (myTitleText != null) {
        myTitleText.setText("Change Order Status");
    }
  /*  Intent in = getIntent();

    // Get XML values from previous intent
    String orderid = in.getStringExtra(KEY_NAME);

    // Displaying all values on the screen
    TextView lblName = (TextView) findViewById(R.id.textView1);


    lblName.setText(orderid); */


    Spinner spinner = (Spinner) findViewById(R.id.spinner1);

    btninsert = (Button)findViewById(R.id.btn_insert1);
    btninsert.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
             Intent in = getIntent();
             String orderid = in.getStringExtra(KEY_NAME);
             String status = in.getStringExtra(KEY_STATUS);
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            PropertyInfo unameProp =new PropertyInfo();
            unameProp.setName("Status");//Define the variable name in the web service method
            unameProp.setValue(selectedItem);//Define value for fname variable
            unameProp.setType(String.class);//Define the type of the variable

            request.addProperty(unameProp);
            PropertyInfo idProp =new PropertyInfo();
            idProp.setName("Orderid");//Define the variable name in the web service method
            idProp.setValue(orderid);//Define value for fname variable
            idProp.setType(String.class);//Define the type of the variable
            request.addProperty(idProp);



              SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
              envelope.setOutputSoapObject(request);
              HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

              try{
               androidHttpTransport.call(SOAP_ACTION, envelope);
                  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

                 TextView result = (TextView) findViewById(R.id.textView2);
                  result.setText(response.toString());
             }
           catch(Exception e){

           }
              }
    });

    //attach the listener to the spinner
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
    //Dynamically generate a spinner data 
    createSpinnerDropDown();

}

//Add animals into spinner dynamically
private void createSpinnerDropDown() {

    //get reference to the spinner from the XML layout
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);

    //Array list of animals to display in the spinner
    List<String> list = new ArrayList<String>();
    Intent in = getIntent();

    String status = in.getStringExtra(KEY_STATUS);
 list.add(status);
list.add("Q");
list.add("P");
list.add("F");
list.add("I");
list.add("C");
int position = -1;
    for(i=0;i<list.size();i++){
        if(list.get(i).equals(status)) {
                position = i;
        }
   }
if(position>0)
   list.remove(position);
    //create an ArrayAdaptar from the String Array
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
    //set the view for the Drop down list
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //set the ArrayAdapter to the spinner
    spinner.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    //attach the listener to the spinner
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

 }
 public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

         selectedItem = parent.getItemAtPosition(pos).toString();

       }


    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }



    }

    public void onNothingSelected(AdapterView<?> parent) {
        // Do nothing.
    }
}
public类InsertionExample扩展活动{
私有最终字符串命名空间=”http://xcart.com";
私有最终字符串URL=”http://192.168.1.168:8089/XcartLogin/services/update?wsdl";
私有最终字符串SOAP_ACTION=”http://xcart.com/insertData";
私有最终字符串方法\u NAME=“insertData”;
按钮BTN插入;
字符串selectedItem;
私人互联网i;
静态最终字符串键\u NAME=“orderid”;
静态最终字符串键\u STATUS=“STATUS”;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
最终布尔值customTitleSupported=requestWindowFeature(Window.FEATURE\u CUSTOM\u TITLE);
setContentView(R.layout.change_状态);
如果(支持自定义标题){
getWindow().setFeatureInt(Window.FEATURE\u CUSTOM\u TITLE,R.layout.Window\u TITLE);
}
最终文本视图myTitleText=(文本视图)findViewById(R.id.mytitle);
如果(myTitleText!=null){
myTitleText.setText(“变更单状态”);
}
/*Intent in=getIntent();
//从以前的意图中获取XML值
字符串orderid=in.getStringExtra(键名称);
//在屏幕上显示所有值
TextView lblName=(TextView)findViewById(R.id.textView1);
lblName.setText(orderid)*/
微调器微调器=(微调器)findViewById(R.id.spinner1);
btninsert=(按钮)findViewById(R.id.btn\u insert1);
btninsert.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
Intent in=getIntent();
字符串orderid=in.getStringExtra(键名称);
字符串状态=in.getStringExtra(键状态);
SoapObject请求=新的SoapObject(名称空间、方法名称);
PropertyInfo unameProp=新的PropertyInfo();
unameProp.setName(“Status”);//在web服务方法中定义变量名
unameProp.setValue(selectedItem);//为fname变量定义值
unameProp.setType(String.class);//定义变量的类型
request.addProperty(unameProp);
PropertyInfo idProp=新的PropertyInfo();
idProp.setName(“Orderid”);//在web服务方法中定义变量名
idProp.setValue(orderid);//定义fname变量的值
idProp.setType(String.class);//定义变量的类型
请求。添加属性(idProp);
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(请求);
HttpTransportSE androidHttpTransport=新的HttpTransportSE(URL);
试一试{
调用(SOAP_操作,信封);
SoapPrimitive响应=(SoapPrimitive)信封.getResponse();
TextView结果=(TextView)findViewById(R.id.textView2);
result.setText(response.toString());
}
捕获(例外e){
}
}
});
//将侦听器附加到微调器
spinner.setOnItemSelectedListener(新的MyOnItemSelectedListener());
//动态生成微调器数据
createSpinnerDropDown();
}
//将动物动态添加到微调器中
私有void createSpinnerDropDown(){
//从XML布局获取对微调器的引用
微调器微调器=(微调器)findViewById(R.id.spinner1);
//要在微调器中显示的动物数组列表
列表=新的ArrayList();
Intent in=getIntent();
字符串状态=in.getStringExtra(键状态);
列表。添加(状态);
列表。添加(“Q”);
列表。添加(“P”);
列表。添加(“F”);
列表。添加(“I”);
列表。添加(“C”);
int位置=-1;
对于(i=0;i0)
列表。删除(位置);
//从字符串数组创建ArrayAdaptar
ArrayAdapter=新的ArrayAdapter(此,
android.R.layout.simple\u微调器\u项目,列表);
//设置下拉列表的视图
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
//将阵列适配器设置为微调器
旋转器。设置适配器(适配器);
adapter.notifyDataSetChanged();
//将侦听器附加到微调器
spinner.setOnItemSelectedListener(新的MyOnItemSelectedListener());
}
公共类MyOnItemSelectedListener实现OnItemSelectedListener{
已选择公共位置(AdapterView父项、视图、整数位置、长id){
selectedItem=parent.getItemAtPosition(pos.toString();
}
@凌驾
未选择公共无效(AdapterView arg0){
//TODO自动生成的方法存根
}
}
未选择公共无效(AdapterView父级){
//什么也不做。
}
}

如何在我的应用程序中创建自定义微调器?

我无法开发此项=>然后发生了什么?任何错误、问题或其他您在
createSpinner下拉列表(Spinner Spinner)
中创建两个
Spinner Spinner的实例,一个在
OnCreate
中,另一个在
createSpinner Dropdown
中通过
Spinner
并使用该对象。可能就是这个问题。这个问题有什么问题。我想为微调器设置背景色。默认情况下,它是选定的黄色。但是我想显示其他颜色。怎么办