Cannot modify a button from the menu

by midicool » Thu, 05 Mar 2009 11:47:24 GMT


Sponsored Links
 Hi,

I am writing a program that has a menu. Once you press the menu button
and then select "Left",  it's supposed to change the attributes of
myButton12, an ImageButton.

However, I am getting a "myButton12 cannot be resolved" error message.
Please help me figure out what is wrong with this code.

Thanks!
-Jimmy



The code:

package com.innodesign.testingbuttons;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AbsoluteLayout;
import android.widget.ImageButton;
import android.widget.Button;
import android.widget.EditText;
import android.net.Uri;
import android.content.Intent;

@SuppressWarnings("unused")
public class TestingButtons extends Activity {
        protected void onCreate(Bundle icicle) {
                super.onCreate(icicle);
                setContentView(R.layout.main);

                final ImageButton myButton12 = (ImageButton) findViewById
(R.id.btid12);
                myButton12.setOnClickListener(new View.OnClickListener()
{
                public void onClick(View v) {
                // Perform action on click
                        phoneNumber.setText(phoneNumber.getText()+"#");
                        }
                });
        }

    @Override
    public boolean onCreateOptionsMenu(Menu menu){
        super.onCreateOptionsMenu(menu);

                menu.add(0, 1, 0, "Left");
                menu.add(0, 2, 0, "Right");
    return true;
    }

        @Override
        public boolean onOptionsItemSelected(MenuItem item){
                switch(item.getItemId()){
                case 1:
                        shiftLeft();
                return true;
                case 2:
                return true;
                }
        return true;
        }

        public void shiftLeft(){
                myButton12.setLayoutParams(new AbsoluteLayout.LayoutParams(10, 
10,
10, 10));

        }
}



--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Service processing restrictions on main thread

I have a service which I start off in a separate process from the
application using "process:myname" tag.

Do I need to be careful to take longish running method calls out of
the main thread, even when the service is in its own process ? I do
some initialization during onCreate/onStart that could take a few
seconds.  I would like to understand what is the implication of
leaving these calls here, or should I take these calls off on to a
separate thread.



--~--~---------~--~----~------------~-------~--~----~

2. What are the possible way to work on database?

Hi,
I have a question in my mind that what are the possible way to work on
databse?
My means, can we create the database in our main file only through
code? OR first create the database using Sqlite manager and then
integrate it to the code.If second option, we can use then it will be
little bit easy comparing to the first method.If second method works
in android then can anyone provide me a sample code for this?
I will be highly obliged for this.
Thanks
Dilu.
--~--~---------~--~----~------------~-------~--~----~

3. Radogroup layout question.

4. How do I make sure one row ListView is always in focus

5. How do I make sure one row ListView is always in focus

6. Netbeans

7. Help on building android source code for omap3430