通过Android App从GoogleSpreadSheet中删除记录或行

时间:2014-01-02 11:19:57

标签: android google-sheets google-spreadsheet-api

我想通过Android App删除Googlespreadsheet中的记录,我使用AndroidApp在GoogleSpreadSheet上成功发布数据,但是我无法从中删除记录,     请帮我把这个prblm问题出来???????????

   My code is:-

   package com.makemyandroidapp.example.googlespreadsheet.post;

   import java.io.IOException;
   import java.net.URL;
   import java.net.URLEncoder;

   import android.app.Activity;
   import android.content.pm.ActivityInfo;
   import android.os.Bundle;
   import android.view.View;
   import android.view.View.OnClickListener;
   import android.view.Window;
   import android.view.WindowManager;
   import android.widget.AdapterView;
   import android.widget.AdapterView.OnItemSelectedListener;
   import android.widget.ArrayAdapter;
   import android.widget.Button;
   import android.widget.EditText;
   import android.widget.RadioButton;
   import android.widget.RadioGroup;
   import android.widget.Spinner;
   import android.widget.TextView;

   import com.google.gdata.client.spreadsheet.SpreadsheetService;
   import com.google.gdata.data.spreadsheet.CustomElementCollection;
   import com.google.gdata.data.spreadsheet.ListEntry;
   import com.google.gdata.data.spreadsheet.ListFeed;
   import com.google.gdata.util.ServiceException;

   public class MainActivity extends Activity {

    final String myTag = "DocsUpload";

    String[] fed = { "Karbon", "Samsung-Phone", "7-inch Tab", "new 7-inch Tab",
            "10-inch Tab", "Zodiac Beetel", "i-Ball Tab", "Nokia-j2me",
            "Samsung-j2me", "Iphone3G", "I-pad", "Iphone4", "BlackBerry" };
    String[] dept = { "Vishuv", "Juhi", "Nitin", "Seema", "Jitendra", "Gaurav",
            "Nitish", "Gagan", "Ankit", "Vivek", "Zakir", "Parveen" };

    Spinner spinfederal, spindepartment;
    ArrayAdapter<String> fedd, dpt;

    RadioGroup rdcable, rdsim, rdcharger;
    EditText Comments;
    String col1, col2;
    Button submit;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        // Remove notification bar
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.activity_main);
        Intialize();

        submit.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    // postData();

                    getdetails();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }
        });

        /*
         * Log.i(myTag, "OnCreate()"); Thread t = new Thread(new Runnable() {
         * 
         * @Override public void run() { postData();
         * 
         * 
         * 
         * } }); t.start();
         */
    }

    public void postData() {

        int selectedOption = rdcable.getCheckedRadioButtonId();
        RadioButton cable = (RadioButton) findViewById(selectedOption);
        String col3 = cable.getText().toString();

        int selectedOptions = rdsim.getCheckedRadioButtonId();
        RadioButton sim = (RadioButton) findViewById(selectedOption);
        String col4 = sim.getText().toString();

        int selectedOptionss = rdcharger.getCheckedRadioButtonId();
        RadioButton charger = (RadioButton) findViewById(selectedOption);
        String col5 = charger.getText().toString();

        String col6 = Comments.getText().toString();

        String fullUrl = "https://docs.google.com/a/decimal.co.in/forms/d/1aAFfMQgVnRBtAl5vU0EiRRZLRjMrahQdl4-WcHNqVYU/formResponse";
        HttpRequest mReq = new HttpRequest();

        String data = "entry_1790195648=" + URLEncoder.encode(col1) + "&"
                + "entry_575748699=" + URLEncoder.encode(col2) + "&"
                + "entry_941008401=" + URLEncoder.encode(col3) + "&"
                + "entry_1659545832=" + URLEncoder.encode(col4) + "&"
                + "entry_1826324241=" + URLEncoder.encode(col5) + "&"
                + "entry_1609446386=" + URLEncoder.encode(col6);
        String response = mReq.sendPost(fullUrl, data);

    }

    public void Intialize() {

        rdcable = (RadioGroup) findViewById(R.id.cable);

        rdsim = (RadioGroup) findViewById(R.id.sim);
        rdcharger = (RadioGroup) findViewById(R.id.charger);

        Comments = (EditText) findViewById(R.id.etcomments);

        submit = (Button) findViewById(R.id.submit);

        spinfederal = (Spinner)       findViewById(R.id.spinner_federalentity_supportform);
        spindepartment = (Spinner) findViewById(R.id.spinner_department_supportform);

        fedd = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, fed);

        fedd.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinfederal.setAdapter(fedd);

        spinfederal.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int pos, long id) {
                col1 = parent.getItemAtPosition(pos).toString();
            }

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

            }
        });

        dpt = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, dept);

        dpt.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spindepartment.setAdapter(dpt);

        spindepartment.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int pos, long id) {
                col2 = parent.getItemAtPosition(pos).toString();
            }

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

            }
        });
    }

    @Override
    public void onBackPressed() {
        setResult(RESULT_OK);
        MainActivity.this.finish();
    }

    public void getdetails() {

        try {

            SpreadsheetService service = new SpreadsheetService("GoogleSpreadSheetPostExample");
              // Notice that the url ends
              // with default/public/values.
              // That wasn't obvious (at least to me)
              // from the documentation.
              String urlString = "https://docs.google.com/a/decimal.co.in/spreadsheet/ccc?key=0Aqctt-aYYlOudGdCWklUN3ZrLXk1V3FWQ3M1dWJ1M2c&usp=sharing#gid=0";

              // turn the string into a URL
              URL url = new URL(urlString);

              // You could substitute a cell feed here in place of
              // the list feed
              ListFeed feed = service.getFeed(url, ListFeed.class);

              for (ListEntry entry : feed.getEntries()) {
                CustomElementCollection elements = entry.getCustomElements();
                String name = elements.getValue("name");
                System.out.println(name);
                String number = elements.getValue("Number");
                System.out.println(number);
              }

            } catch (IOException e) {
              e.printStackTrace();
            } catch (ServiceException e) {
              e.printStackTrace();
            }
    }

      }

1 个答案:

答案 0 :(得分:0)

它比添加一行更简单..我还没有测试下面的代码,但是这应该可行(它适用于我的c#代码)。

ListFeed feed = service.getFeed(url, ListFeed.class);
for (ListEntry entry : feed.getEntries()) {
   if(...is this the row to delete...)
       entry.delete();
}