IntelliJ IDEA for Android Development

Monday, January 10, 2011

imageI really like IntelliJ IDEA - and the free community edition now supports Google Android development.

Part of the reason I like this IDE is because it feels familiar. I've learned the JetBrains sense of style from using ReSharper in Visual Studio, and seeing familiar commands for navigation and refactoring is comforting. It's great to have the muscle memory for Alt+Enter and Alt+Insert, and the auto-completion works well both for Java code and XML resources (which is a tremendous help for someone new to the platform, like myself).

Now I find myself in the wiring up UI events in Java, which feels awkward and verbose coming from C#. I'm also learning the difference between a click and a long click in Android. If you return false from the long click event handler, the event is unhandled and the regular click event handler will also fire. If you return true, the system considers the event handled and the regular click event doesn't fire.

 

public class MainActivity extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState)     {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        textView = (TextView)findViewById(R.id.text);
        button =(Button)findViewById(R.id.button);

        button.setOnClickListener(buttonClickListener);
        button.setOnLongClickListener(buttonLongClickListener);
    }

    View.OnClickListener buttonClickListener = new View.OnClickListener(){
        public void onClick(View v) {
            textView.setText("Clicked");
        }
    };

    View.OnLongClickListener buttonLongClickListener = new View.OnLongClickListener() {
        public boolean onLongClick(View v){
            textView.setText("Long click");
            return true;
        }
    };

    private Button button;
    private TextView textView;
}

Comments
Comments are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!