Hoping to change widget attributes by selecting a menu item

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

Sponsored Links

I am writing a program that involves a menu. Once you press the menu
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.


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;

public class TestingButtons extends Activity {
       protected void onCreate(Bundle icicle) {

               final ImageButton myButton12 = (ImageButton)
               myButton12.setOnClickListener(new View.OnClickListener
               public void onClick(View v) {
               // Perform action on click

   public boolean onCreateOptionsMenu(Menu menu){

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

       public boolean onOptionsItemSelected(MenuItem item){
               case 1:
               return true;
               case 2:
               return true;
       return true;

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



Hoping to change widget attributes by selecting a menu item

by Jesse McGrew » Thu, 05 Mar 2009 13:14:11 GMT


You've defined myButton12 as a local variable for the onCreate()
method. It doesn't exist in shiftLeft(), so you're getting that error

Define myButton12 as a field of your activity class instead so it can
be used from the other methods:

  public class TestingButtons extends Activity {
      private ImageButton myButton12;
      /* ... */

Then remove the words "final ImageButton" from the line in onCreate()
where you assign to myButton12.


Sponsored Links

Other Threads

1. Framework support for detecting starting and stopping of activities

To support usability studies on what applications are used, i want to
write a service that logs when an activity is started and also when it
has finished.  This is to understand how the users are using the

One straightforward option is to have the applications modify, to
write this out.  But this is tedious having to modify all applications
and will not work esp with third party or built in applications.

Is there any alternatives that makes this simpler and easier?

BTW: Looking at the android framework source ActivityManagerNative
seems to be invoking a Binder interface when an Activity is started
and finished.  Any information on what this service is?   Is this
something i can tap into?

Apologizes if i am looking at the wrong code, my first foray in to the
framework code.

Any information or thoughts is greatly appreciated.


2. How do I make a ListView scrollbar expand whilst scrolling?

Also, to get the A-Z overlay when using fastScrollEnabled, you'll need
to implement SectionIndexer for your adapter.  Something like
AlphabetIndexer works great if you have a sorted Cursor.



Jeff Sharkey


3. read from local socket does not work

4. get Certificates from Package

5. SQLLite constraint on delete cascade

6. what problem is the log.....

7. open socket failed: Permission denied when application to run a native C function.