Saturday 16 October 2010

Switching Activies with OnClick

I've read through a lot of examples of how to switch through an activity but I have found that when you create your menu page activity the best practise is to implement the onlick listener directly.

This way you can easily and quickly code your buttons in one case statement




public class Example extends Activity implements OnClickListener

View btnExample = (ImageButton)findViewById(R.id.btnExample);
btnNewItem.setOnClickListener(this);

//On click for the buttons
@Override
public void onClick(View v) {

switch (v.getId()){
case R.id.btnExample:
startActivity(new Intent(this, MainList.class));
break;
//Add more if needed

No comments:

Post a Comment