Saturday, 27 August 2016

Create OnClick Function on The Android



Implementation onClick on the Android

Hello world. Today i wanna show you how to implementation onClick on the android programming. Basically onClick function can use for all widget in android. Something like Textview, Textfield, Button, etc. So on this post i will show you onClick just in Textview. Here we go.

This my basic layout, i call it fragment_one.xml.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="@dimen/activity_horizontal_margin_twice">

    <TextView
        android:id="@+id/tvOne"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16dp"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:text="@string/fragmentOne"/>

    <View
        android:id="@+id/vOne"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorAccent"
        android:layout_marginTop="@dimen/activity_horizontal_margin"
        android:layout_below="@+id/tvOne"/>

    <TextView
        android:id="@+id/tvOnClick"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16dp"
        android:layout_below="@+id/vOne"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:text="@string/onClick"/>

    <View
        android:id="@+id/vTwo"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorAccent"
        android:layout_marginTop="@dimen/activity_horizontal_margin"
        android:layout_below="@+id/tvOnClick"/>

</RelativeLayout>

and on this layout i've two textview that i will to implement click. And this is my function to implement my textview onClick.

private void onClick(View view){
        tvOne = (TextView) view.findViewById(R.id.tvOne);
        tvOnClick = (TextView) view.findViewById(R.id.tvOnClick);
        tvOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Snackbar.make(v, "Hi i am function onclick", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
        tvOnClick.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Snackbar.make(v, "Hi i am function onclick", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

On this function i just declare my text view and call setOnClickListener . And then i put snack bar to show "Hi i am function onClick". It would be like this one.


onClick implementation Function with Snackbar



You can write comment bellow or comment on the my Github page. And also you can download it on my Github page.


Share:
Lokasi: Cilandak, South Jakarta City, Special Capital Region of Jakarta, Indonesia

12 comments:

  1. Thank you for sharing your thoughts and knowledge on this topic. This is really helpful and informative.

    If you want to make custom website & application you can contact us on our Android Application Development and Top Mobile App Development Company anytime.

    ReplyDelete
  2. private void onClick(View view){
    tvOne = (TextView) viewhttp://learnopenerp.blogspot.com/2018/08/odoo-web-controller.htmlfindViewById(R.id.tvOne);
    tvOnClick = (TextView) view.findViewById(R.id.tvOnClick);
    tvOne.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    Snackbar.make(v, "Hi i am function onclick", Snackbar.LENGTH_LONG)
    .setAction("Action", null).show();
    }
    });
    tvOnClick.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    Snackbar.make(v, "Hi i am function onclick", Snackbar.LENGTH_LONG)
    .setAction("Action", null).show();
    }
    });
    }

    here what is set action

    ReplyDelete
  3. Acessing the core of any website or software to customize it and develop a quality product, InnovationM is known for its quality assured handcrafted technological solution, going from software development to website design and Mobile application development. InnovationM is the best Mobile app development and Website design Company in London, UK.

    We are a Software development and web design company providing custom website solutions, law firm web design services in derby, Luton, Birmingham, Sheffield, Derby, and London, UK, and also popularly known for website development in cambridge birmingham, android app design agency derby, software design agency derby, mobile app design agency derby, app developers luton, software design company derby, app development luton, ios app development company derby, mobile app design derby, iphone app development company derby, bespoke app development derby, software app development derby, android app development company in derby, software development company brighton, app agency oxford, mobile app development company derby, iphone app development derby, ios app development derby, development agency brighton, UK.

    And that what we have been known for, InnovationM delivers a quality assure product/ service which is fully dependent on your next virtual need.
    For more: www.innovationm.co.uk

    ReplyDelete
  4. You have really shared a super amazing post! Looking for the best mobile app development company in Delhi? InstaaCoders is the leading mobile app development company, if you're interested to design your personalised mobile applications, then contact us.

    ReplyDelete
  5. If you want the best Android App Development Company in India, who provide the best services. Don't worry, planet web solution is the best Android App Development Company, who provided you Development service, for more information, visit us!

    ReplyDelete
  6. I have just developed the android version of my website Instagb. This feature has really helped me a lot. Thanks

    ReplyDelete
  7. Greetings! Today, I'd like to guide you through implementing the onClick functionality in Android programming. The onClick function is versatile and can be used with various widgets such as TextViews, TextFields, and Buttons. In this example, I'll demonstrate how to apply onClick specifically to a TextView.
    Nix Injector Apk

    ReplyDelete
  8. Hello! It sounds like you're about to provide a tutorial on implementing the `onClick` functionality in Android programming, specifically for TextView widgets. This is a valuable skill as it allows you to create interactive elements fesco bill within your Android apps. If you're ready, please proceed with your tutorial. If you have any specific steps or code samples you'd like to share, feel free to provide them, and I'll be here to assist or provide feedback if needed.

    ReplyDelete
  9. FESCO, or Faisalabad Electric Supply Company, is a government-owned electric distribution company in Pakistan. It is responsible for supplying electricity to the Faisalabad region and its surrounding areas. FESCO issues monthly electricity bills to its customers based on their usage, which includes charges for consumption, meter rent, and various taxes. Customers can pay their bills through various payment methods, such as online banking, mobile apps, and designated bank branches. Timely payment of fesco bill Online is essential to avoid disconnection of electricity services and additional penalties.

    ReplyDelete
  10. Excellent aeticle, it help me to clear my doubt and waiting for your new blog on Custom Web Application Development

    ReplyDelete


<br>


Advice for contacting me at dedyy54@gmail.com