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. Gravity of ImageView inside TableLayout

I have a class which extends from TableLayout:

public class EntryCallLog extends TableLayout {

I defined two columns and I have two TableRows.
Therefore there are two Views inside a Row.
The first should be gravity left the second should be gravity right.
So I can not use tablerow.setGravity(Gravity.Right), because this is
for the whole row.

I tried this one, but it doesnt work!

-------------------------------------------------------
callType = new ImageView(context); // My ImageView

LinearLayout.LayoutParams params = new LayoutParams();
params.gravity = Gravity.RIGHT;

callType.setLayoutParams(params);
row1.addView(callType, 1);
-------------------------------------------------------

I want to set the gravity for one View, should be possible or not?

Thanks a lot!
Thomas



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

2. Question about music player in Opencore 2.04

Hi. This is probably a silly question but I just need confirmation. In
the music player application in Opencore 2.0 we had a test case were
pressing 150 short keys should not result in any strange behavior in
the audio playback. Now the testing team has reported that in opencore
2.04 when you press certain keys a fast forward or rewind (depending
on the key) in the playback is seen. I think this is expected so the
user does not depend on the touchscreen to make seek operations.

Can someone confirm if this is expected behavior for the music player
in Opencore 2.04?

Thanks!

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

3. sdcard mount detection

4. Socket connection

5. Network query apis

6. How to assign/get the ip address of an emulator

7. How to connect content provider in ProviderTestCase2 class?