0

我正在使用以下代码。

nextButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

               String name=nameEdit.getText().toString();

               String contactnumber=numberEdit.getText().toString();

                String quantity = String.valueOf(quantitySpinner.getSelectedItem());

                String noofpieces=piecesEdit.getText().toString();

                String dateandtime=editDateTime.getText().toString();



                String deliveryaddress=deliveryEdit.getText().toString();


                long val=adapter.insertDetails(name, contactnumber, quantity, noofpieces, dateandtime,OPTIONS ,deliveryaddress);


                String sms="Name:"+name+ System.getProperty ("line.separator")+"ContactNumber:"+contactnumber+ System.getProperty ("line.separator")+"Quantity:"+quantity+System.getProperty ("line.separator")+"Number.of.Pcs:"+noofpieces+System.getProperty ("line.separator")+"Date and Time:"+dateandtime+System.getProperty ("line.separator")+"Delivary Address:"+deliveryaddress;

                int bookingId = adapter.getMaxID();

                Bundle passdata = new Bundle();
                passdata.putInt(helper_ob.B_ID, bookingId);
                passdata.putString(helper_ob.QUANTITY, quantity);
                passdata.putString(helper_ob.SMS, sms);
                Intent passIntent = new Intent(BookingForm.this, OrderSummary.class);
                passIntent.putExtras(passdata);
                startActivity(passIntent);finish();

            }
        });

并已插入数据库表。在更新预订表单时。我可以编辑除微调器之外的所有内容。微调器值设置为默认值。

微调器.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Android</string>
    <string name="action_settings">Settings</string>
     <string name="bottle_prompt">Select your Quantity</string>

    <string-array name="bottle_arrays">
        <item >300ml</item>
        <item>500ml</item>
        <item>1-litre</item>
        <item>2-litre</item>
        <item>5-litre</item>
        <item>20-litre</item>
        <item>50-litre</item>
        <item>New Bt</item>
        <item>New Matca</item>
    </string-array>

</resources>

例如:如果我在微调器中选择 1 升并插入到数据库表中,同时更新所有值都会在编辑页面中打开,除了微调器设置为默认 300ml。如何在编辑页面时更新微调器?

编辑.java

package com.example.android;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;

public class EditBookingForm extends Activity {
    EditText nameEdit,contactNumber,editPieces,editDate,editAddress;
    Spinner spinner;
    RadioGroup radioGroup;
    RadioButton radioButton;
    Cursor cursor;
    BookingAdapter adapter;
    BookingOpenHelper openHelper_ob;
    Button doneButton,cancelButton; 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_online);
        nameEdit=(EditText) findViewById(R.id.nameEdit);
        contactNumber=(EditText) findViewById(R.id.contactNumber);
        editPieces=(EditText) findViewById(R.id.editpieces);
        editDate=(EditText) findViewById(R.id.editdate);
        editAddress=(EditText) findViewById(R.id.editdelivary);
        spinner=(Spinner) findViewById(R.id.spinner);
        radioGroup=(RadioGroup) findViewById(R.id.radioGroup);
        doneButton=(Button) findViewById(R.id.updateformbtn);
        cancelButton=(Button) findViewById(R.id.deleteformbutton);      
        Bundle extras = getIntent().getExtras();
        final int bookingId = extras.getInt(openHelper_ob.B_ID);



        adapter = new BookingAdapter(this);
        cursor = adapter.queryAll(bookingId);
        if (cursor.moveToFirst()) {
            do {
                nameEdit.setText(cursor.getString(1));
                contactNumber.setText(cursor.getString(2));
                //spinner.setSelection(q);
                editPieces.setText(cursor.getString(4));
                editDate.setText(cursor.getString(5));
                editAddress.setText(cursor.getString(6));


            } while (cursor.moveToNext());
        }
        doneButton.setOnClickListener(new OnClickListener() {       
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                String name = nameEdit.getText().toString();
                String number = contactNumber.getText().toString(); 
                String quantity = String.valueOf(spinner.getSelectedItem());

                String noofpieces=editPieces.getText().toString();

                String dateandtime=editDate.getText().toString();



                String deliveryaddress=editAddress.getText().toString();

                adapter.updateldetail(bookingId,name,number);
                finish();               
                Bundle passdata = new Bundle();
                String sms="Name:"+name+ System.getProperty ("line.separator")+"ContactNumber:"+number+ System.getProperty ("line.separator")+"Quantity:"+quantity+System.getProperty ("line.separator")+"Number.of.Pcs:"+noofpieces+System.getProperty ("line.separator")+"Date and Time:"+dateandtime+System.getProperty ("line.separator")+"Delivary Address:"+deliveryaddress;
                passdata.putInt(openHelper_ob.B_ID, bookingId);     
                passdata.putString(openHelper_ob.SMS, sms);
                Intent passIntent = new Intent(EditBookingForm.this, OrderSummary.class);
                passIntent.putExtras(passdata);
                startActivity(passIntent);              
            }
        });
}
}
4

3 回答 3

1

获取微调器选择的方法是:

int spinnerValue = spinner.getSelectedItemPosition();

文档参考: http: //developer.android.com/reference/android/widget/AdapterView.html#getSelectedItemPosition()

于 2013-09-26T06:12:48.743 回答
0
spinner.setSelection(POSITION);

这会将选择设置为可以从字符串文件中的数组元素中找到位置的所需位置

于 2013-09-26T06:01:17.200 回答
0
Spinner spinner;

//以数量存储文本值

String quantity = String.valueOf(spinner.getSelectedItem());

//将getSelectedItemPosition存储在int变量中

int qualityValue=spinner.getSelectedItemPosition();
于 2013-09-26T09:44:39.890 回答