Search in sources :

Example 81 with OnClickListener

use of android.view.View.OnClickListener in project coursera-android by aporter.

the class ButtonActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // Get a reference to the Press Me Button
    final Button button = (Button) findViewById(R.id.button);
    // Set an OnClickListener on this Button
    // Called each time the user clicks the Button
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Maintain a count of user presses
            // Display count as text on the Button
            button.setText("Got Pressed:" + ++count);
        }
    });
}
Also used : Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) View(android.view.View)

Example 82 with OnClickListener

use of android.view.View.OnClickListener in project coursera-android by aporter.

the class CheckBoxActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // Get a reference to the CheckBox
    final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
    // Set an OnClickListener on the CheckBox
    checkbox.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Set CheckBox text accordingly
            if (checkbox.isChecked()) {
                checkbox.setText("I'm checked");
            } else {
                checkbox.setText("I'm not checked");
            }
        }
    });
    // Get a reference to the Hide CheckBox Button
    final Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // Set the Button text accordingly
            if (checkbox.isShown()) {
                checkbox.setVisibility(View.INVISIBLE);
                button.setText("Unhide CheckBox");
            } else {
                checkbox.setVisibility(View.VISIBLE);
                button.setText("Hide CheckBox");
            }
        }
    });
}
Also used : Button(android.widget.Button) CheckBox(android.widget.CheckBox) OnClickListener(android.view.View.OnClickListener) View(android.view.View)

Example 83 with OnClickListener

use of android.view.View.OnClickListener in project coursera-android by aporter.

the class RelativeLayoutActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final EditText textEntry = (EditText) findViewById(R.id.entry);
    final Button cancelButton = (Button) findViewById(R.id.cancel_button);
    cancelButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // Clear the textEntry
            textEntry.setText("");
        }
    });
    final Button okButton = (Button) findViewById(R.id.ok_button);
    okButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // Finish the application
            RelativeLayoutActivity.this.finish();
        }
    });
}
Also used : EditText(android.widget.EditText) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) View(android.view.View)

Example 84 with OnClickListener

use of android.view.View.OnClickListener in project coursera-android by aporter.

the class SamplerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // 
    final ImageButton button = (ImageButton) findViewById(R.id.button);
    button.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // Show Toast message 
            Toast.makeText(SamplerActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
        }
    });
    final EditText edittext = (EditText) findViewById(R.id.edittext);
    edittext.setOnKeyListener(new OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "Done" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Show Toast message 
                Toast.makeText(SamplerActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                return true;
            }
            return false;
        }
    });
    final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
    checkbox.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // Show Toast message indicating the CheckBox's Checked state
            if (((CheckBox) v).isChecked()) {
                Toast.makeText(SamplerActivity.this, "CheckBox checked", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(SamplerActivity.this, "CheckBox not checked", Toast.LENGTH_SHORT).show();
            }
        }
    });
    final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
    final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
    radio_red.setOnClickListener(radio_listener);
    radio_blue.setOnClickListener(radio_listener);
    final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
    togglebutton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // Perform action on clicks
            if (togglebutton.isChecked()) {
                Toast.makeText(SamplerActivity.this, "ToggleButton checked", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(SamplerActivity.this, "ToggleButton not checked", Toast.LENGTH_SHORT).show();
            }
        }
    });
    final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar);
    ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
            Toast.makeText(SamplerActivity.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : EditText(android.widget.EditText) ToggleButton(android.widget.ToggleButton) OnRatingBarChangeListener(android.widget.RatingBar.OnRatingBarChangeListener) RadioButton(android.widget.RadioButton) View(android.view.View) RatingBar(android.widget.RatingBar) KeyEvent(android.view.KeyEvent) ImageButton(android.widget.ImageButton) CheckBox(android.widget.CheckBox) OnClickListener(android.view.View.OnClickListener) OnKeyListener(android.view.View.OnKeyListener)

Example 85 with OnClickListener

use of android.view.View.OnClickListener in project coursera-android by aporter.

the class NetworkingAndroidHttpClientActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mTextView = (TextView) findViewById(R.id.textView1);
    final Button loadButton = (Button) findViewById(R.id.button1);
    loadButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            new HttpGetTask().execute();
        }
    });
}
Also used : Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) View(android.view.View)

Aggregations

OnClickListener (android.view.View.OnClickListener)794 View (android.view.View)792 TextView (android.widget.TextView)492 Button (android.widget.Button)265 ImageView (android.widget.ImageView)256 Intent (android.content.Intent)183 ListView (android.widget.ListView)112 AdapterView (android.widget.AdapterView)91 ScrollView (android.widget.ScrollView)52 LinearLayout (android.widget.LinearLayout)49 Bundle (android.os.Bundle)43 LayoutInflater (android.view.LayoutInflater)35 ViewGroup (android.view.ViewGroup)30 ArrayList (java.util.ArrayList)30 BindView (butterknife.BindView)29 KeyEvent (android.view.KeyEvent)28 EditText (android.widget.EditText)28 DialogInterface (android.content.DialogInterface)27 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)25 FragmentManager (android.support.v4.app.FragmentManager)23