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 に設定されていることを除いて、すべての値が編集ページで開かれます。

Edit.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