Skip to content Skip to sidebar Skip to footer

Setcontentview And Listeners

I'm changing my ContentView of the Activity at some point. (to View2). After changing it back to View1, the listeners are not more working. I already tried putting the Listener in

Solution 1:

Thank you all, for your reply. You made me realize, the onClickListeners are getting lost when I remove or replace (using setContentView()) the main view. I ended up this way now:

onCreate:

setContentView(R.layout.parse);
LinearLayoutcontainer= (LinearLayout) findViewById(R.id.container);
container.addView(getLayoutInflater().inflate(R.layout.dialog, null));
container.addView(getLayoutInflater().inflate(R.layout.progress, null));

onStartDoingSomething:

findViewById(R.id.dialog).setVisibility(View.INVISIBLE);
findViewById(R.id.progress).setVisibility(View.VISIBLE);

onEndDoingSomehting:

findViewById(R.id.dialog).setVisibility(View.VISIBLE);
findViewById(R.id.progress).setVisibility(View.INVISIBLE);

I might change View.INVISIBLE to View.GONE, like nmr said, but since I have never used View.GONE, I have to check the Android doku first ;)

Solution 2:

Solution 3:

You can only have one UI for each Activity, you should create another activity and in its onCreate method set the content view

Steps:

  1. Create Activity
  2. Use the following code to set the content View:

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view2);

    }

  3. Define the Activity in the applications manifest as such :

  4. Create an intent in the first Activity:

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view1);

    Button button = (Button) findViewById(R.id.button);

    button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { intent(); } }); }

    void intent(){

    Intent intent = new Intent();intent.setClass(Activity1.this, Activity2.class); startActivity(intent);

    }

And there you go c:

Post a Comment for "Setcontentview And Listeners"