1

嗨,我想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="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.
    }
}

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

4

0 回答 0