Saturday, 27 August 2016

Implementation Function Handler Android (show anything after a few second)



Implementation Function Handler Android (show anything after a few second)


Hello world. Today its my second post, ya i wanna show you how to implementation function handler on the android programming. If you don't know about handler, handler is like function that you can use, if you want to show anything, with period. For example i wanna show snackbar or anything after 3 second. Lets do it.

Ahha, i've handler function like this.

private void handlerFunction(final View v){
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Snackbar.make(v, "Hi i am show after  3 second", 
                        Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        }, 3000);
    }

On this function, i just 3000 millisecond its mean 3 second waiting. And after that snackbar will show like this "Hi i am show after 3 second". Like this picture.


Implement Handler Function


If you want to show anything, you put inside run function. Just it. Write comment bellow if still confuse about my code, or comment on my Github page. I hope this is can help you little bit. Lol. Thanks.

Github page.

Share:

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:

Friday, 29 July 2016

How to Inherit Function Odoo ?



https://dedyyuristiawan.blogspot.co.id


Hello wold. Today i got inspiration from my comment's. He just started develop Odoo. You know, actually i am so appreciate that, maybe we feel difficult to learn something new, and we don't have person to help us, just world wide web. I know, because for first time I learn Odoo, i feel so disappointed for myself, I just think 'i can't do it'. But i keep learn Odoo, cause i am still work with company use Odoo aha. But huyaa for time by time i can learn the process Odoo, new syntax from python, qweb, or maybe js, css, etc cause my background its not from website. And you know, now i am realise that how's can develop Odoo is easy, i am so realise that. Just little bit share my misery. Lol

So just go ahead right? today i am gonna share about how to inherit function Odoo, for example in this post i will inherit function create. Just for note, function create is automatically create when we develop view form or tree. Aha you know function create in base Odoo, it always have the name 'create'. And usually have one parameter is self or two parameter is self, vals (variable that we have). For example in Odoo base, we have create like this.

@api.model
def create(self, vals):
    .
    .
    .
    .
    return A

As you can see create have two variable, self and vals. And now i want to inherit that. see my code.

class AddFieldProduct (models.Model):
    _inherit = "product.template"    
 
    info = fields.Char('Info') 

    @api.model
    def create(self, vals):
        if self.info :
            self.info = 'is a field info'
        return super(AddFieldProduct, self).create(vals)

as you can see, the requirement is :

1. We need to create file something like me, i create file inherit_function.py and then we need to create class like 'class inherit_function (models.Model)' and type class 'model'.

2. Declaration class with _inherit = "product.template", it mean we want to inherit model product.product.

3. Write name and parameter, similar with function, see def create(self, vals) and add @api.model above the function.

4. Add what you what you want need. Like this one i just want to set field info is 'is a field info'. if self.info : self.info = 0

5. And last add return with super like this one, return super(inherit_function, self).create(vals). inherit_function is a my class, see on the top.

7. When we inherit create like that, we put there condition on the function, field info will save 'is a field info' in database. trust me.

6. That's it, easy right? 

So the conclusion is Semangat!! like my boss always say to me, when i got problem with my code. Lol


Share:


<br>


Advice for contacting me at dedyy54@gmail.com