开发者

press button makes spinner visible in another screen

I'm trying to code an onClickevent button on screen 1 that makes a spinner visible or invisible, depends of the needs, on screen 2 as a result.

Knowing that on screen 1 there are several buttons which uses the same views or widgets on the second screen, I was thinking about it to use one screen for all these activities.

It would be nice if someone knows and explain to me how to solve this problem.

I will attach the java code just to look at it.

public class screen1 extends Activity {

    private View spinner1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.screen1);

        spinner1 = findViewById(R.id.spinner1);
        Button A = (Button) findViewById(R.开发者_Go百科id.b_A);

     // error output: Cannot instantiate the type View.OnClickListener
            A.setOnClickListener(new View.OnClickListener());
        A.setOnClickListener(mVisibleListener);
        }   

                        @Override
// error output behind the line 'public void':The method onClick(View) of type screen1 must override or implement a supertype method

            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                startActivity(new Intent("com.jack.test.SCREENMENU"));

            }
            OnClickListener mVisibleListener = new OnClickListener(){
                public void onClick(View v){
                    spinner1.setVisibility(View.VISIBLE);{
        };    
                       // the rest is ok from here to down.


You seem to have some major glitches going on with the code in addition to what you are asking. Fortunately, if I understand you correctly, the thing you want is easy to fix:

@Override
public void onClick(DialogInterface dialog, int which)
{
    if (need_is_met)
        {
        if (spinner1.getVisibility() == View.INVISIBLE)
            view.setVisibility(View.VISIBLE);
        else
            view.setVisibility(View.INVISIBLE);
        }
}

need_is_met is a boolean ... thats as far as i could get with your statement "depends of the needs"

as far as the rest of your code, it should read like this:

public class screen1 extends Activity
    {

    private View spinner1;

    @Override
    protected void onCreate(Bundle savedInstanceState)
        {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.screen1);
        boolean need_is_met = true; // you can change this or have it set based on something later if you want
        spinnerAutomerk = findViewById(R.id.spinnerAutomerk);
        button_A = (Button) findViewById(R.id.b_A);

        button_A.setOnClickListener(new View.OnClickListener()
            {
            @Override
            public void onClick(View v)
                {
                if (need_is_met)
                    {
                    if (spinnerAutomerk.getVisibility() == View.INVISIBLE)
                        spinnerAutomerk.setVisibility(View.VISIBLE);
                    else
                spinnerAutomerk.setVisibility(View.INVISIBLE);
                    }
            }
            }
        }
    }

something like that. i took out all the requestWindowFeature, windowFlag etc because it is much neater to put this into your manifest:

...
<application
    android:icon="@drawable/icon" 
    android:label="@string/app_name"
    >
  <activity
        android:name=".Screen1"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
...

that last line, the theme bit, will set you up with any one of a number of themes (such as dark, light, transparent etc. just got to R.style and ctrl-F for theme and youll see there is a number to choose from. similar to this they can kill the title and notification bar, if you wish. also i didnt to set net_is_met to something because i dont know what the rest of your code is about.


First off all you need to have screen2 as another activity if you want it to open when clicked and show the spinner (not sure if that is exactly what you meant).

You should use intents to switch to screen2's activity. There a billion examples on how to do that if you google it.

You would use a Boolean to check if certain requirements are met or not:

Boolean Reqs = false;
If(req_met){
    Reqs = true;
} else {
    Reqs = false;
}

Use that type of format then check if Reqs is true or not when sending the intent to see if the spinner is visible or not (I would use another intent for that)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜