Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9035303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:43:31+00:00 2026-06-16T08:43:31+00:00

Title says it all, Im new to SQL and trying to change the selection

  • 0

Title says it all, Im new to SQL and trying to change the selection the user makes but placing buttons in the screen and not use the MENU button. Seems like the buttons aren’t instantiated but the code looks right to me…what am i missing??

package com.example.worldcountriesbooks;

import android.app.Activity;
 import android.app.AlertDialog;
 import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class ViewCountry extends Activity implements OnClickListener{


   private long rowID;
   private TextView nameTv;
   private TextView capTv;
   private TextView codeTv; 
   private TextView newEt;




   @Override
   public void onCreate(Bundle savedInstanceState) 
   {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.view_country);
      Button a = (Button)findViewById(R.id.editbutton);
       Button b = (Button)findViewById(R.id.deletebutton);
      a.setOnClickListener(this);
      b.setOnClickListener(this); //Set them up right here...

      setUpViews();
      Bundle extras = getIntent().getExtras();
      rowID = extras.getLong(CountryList.ROW_ID); 
   }

   private void setUpViews() {
       nameTv = (TextView) findViewById(R.id.nameText);
       capTv = (TextView) findViewById(R.id.capText);
       codeTv = (TextView) findViewById(R.id.codeText);
       newEt = (TextView)findViewById(R.id.newText);

   }

   @Override
   protected void onResume()
   {
      super.onResume();
      new LoadContacts().execute(rowID);
   } 

   private class LoadContacts extends AsyncTask<Long, Object, Cursor> 
   {
      DatabaseConnector dbConnector = new DatabaseConnector(ViewCountry.this);

      @Override
      protected Cursor doInBackground(Long... params)
      {
         dbConnector.open();
         return dbConnector.getOneContact(params[0]);
      } 

      @Override
      protected void onPostExecute(Cursor result)
      {
         super.onPostExecute(result);

         result.moveToFirst();
         // get the column index for each data item
         int nameIndex = result.getColumnIndex("name");
         int capIndex = result.getColumnIndex("cap");
         int codeIndex = result.getColumnIndex("code");
         int newIndex = result.getColumnIndex("newb");


         nameTv.setText(result.getString(nameIndex));
         capTv.setText(result.getString(capIndex));
         codeTv.setText(result.getString(codeIndex));
         newEt.setText(result.getString(newIndex));


         result.close();
         dbConnector.close();
      }
   } 


   @Override
   public boolean onCreateOptionsMenu(Menu menu) 
   {
      super.onCreateOptionsMenu(menu);
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.view_country_menu, menu);
      return true;
   }


   @Override
   public boolean onOptionsItemSelected(MenuItem item) 
   {
      switch (item.getItemId())
      {
         case R.id.editItem:
            Intent addEditContact =
               new Intent(this, AddEditCountry.class);

            addEditContact.putExtra(CountryList.ROW_ID, rowID);
            addEditContact.putExtra("name", nameTv.getText());
            addEditContact.putExtra("cap", capTv.getText());
            addEditContact.putExtra("code", codeTv.getText());
            addEditContact.putExtra("newb", newEt.getText());

            startActivity(addEditContact); 
            return true;

         case R.id.deleteItem:
            deleteContact();
            return true;

         default:
            return super.onOptionsItemSelected(item);
      } 
   }
   private void deleteContact()
   {

      AlertDialog.Builder alert = new AlertDialog.Builder(ViewCountry.this);

      alert.setTitle(R.string.confirmTitle); 
      alert.setMessage(R.string.confirmMessage); 

      alert.setPositiveButton(R.string.delete_btn,
         new DialogInterface.OnClickListener()
         {
            public void onClick(DialogInterface dialog, int button)
            {
               final DatabaseConnector dbConnector = 
                  new DatabaseConnector(ViewCountry.this);

               AsyncTask<Long, Object, Object> deleteTask =
                  new AsyncTask<Long, Object, Object>()
                  {
                     @Override
                     protected Object doInBackground(Long... params)
                     {
                        dbConnector.deleteContact(params[0]); 
                        return null;
                     } 

                     @Override
                     protected void onPostExecute(Object result)
                     {
                        finish(); 
                     }
                  };

               deleteTask.execute(new Long[] { rowID });               
            }
         }
      );

      alert.setNegativeButton(R.string.cancel_btn, null).show();
   }

public void onClick(View arg0) {
     switch (arg0.getId())
      {
         case R.id.editItem:
            Intent addEditContact =
               new Intent(this, AddEditCountry.class);

            addEditContact.putExtra(CountryList.ROW_ID, rowID);
            addEditContact.putExtra("name", nameTv.getText());
            addEditContact.putExtra("cap", capTv.getText());
            addEditContact.putExtra("code", codeTv.getText());
            addEditContact.putExtra("newb", newEt.getText());

                startActivity(addEditContact); 
                break;

             case R.id.deleteItem:
                deleteContact();
                break;//finish them up here and they do nothing...

    }
    }
}

Now the menu buttons work great so not sure whats up…Thanks for looking

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:43:32+00:00Added an answer on June 16, 2026 at 8:43 am

    The menu buttons work great because the switch statement for it is proper.

    Your onClick is not working properly however. This is because The cases are for different ids than what the buttons provide. You want R.id.editbutton and R.id.deletebutton instead.

    Your method should look like:

    public void onClick(View arg0) {
         switch (arg0.getId())
          {
             case R.id.editbutton: //updated
                Intent addEditContact =
                   new Intent(this, AddEditCountry.class);
    
                addEditContact.putExtra(CountryList.ROW_ID, rowID);
                addEditContact.putExtra("name", nameTv.getText());
                addEditContact.putExtra("cap", capTv.getText());
                addEditContact.putExtra("code", codeTv.getText());
                addEditContact.putExtra("newb", newEt.getText());
    
                    startActivity(addEditContact); 
                    break;
    
                 case R.id.deletebutton: //updated
                    deleteContact();
                    break;
    
        }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title pretty much says it all, but in SQL Server 2005 Management Studio,
As the title says, I'm trying to change the ID of all elements with
as the title says I'm trying to list all cars of one specific user,
Title says all. Sample code: ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>(); HashMap<String, Object>
The title pretty much says it all, but basically I have a main parent
Well the title pretty much says it all. I had: $strata = new Zend_Form_Element_Select('strata');
The title basically says it all. I'm getting three user-supplied integers ( year ,
Title pretty much says it all. I'm moving to a new computer setup and
Title kinda says it all. The usual SOS command !bpmd doesn't do a lot
Title pretty much says it all. The web.config, unchanged from how VS2008SP1 generated it,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.