Latest Android Studio Navigation Drawer Tutorial (Part 2) - 2016

Latest Android Studio Navigation Drawer Tutorial (Part 2) - 2016 - Hello friends Android tutorial and tips trik, The article you are reading this time with the title Latest Android Studio Navigation Drawer Tutorial (Part 2) - 2016, we have prepared this article for you to read and download the information therein. hopefully fill posts article -, article (LATEST, article (Part, article 2), article 2016, article android, article Drawer, article Navigation, article Studio, article Tutorial, we can write this you understand. Well, happy reading.

Title : Latest Android Studio Navigation Drawer Tutorial (Part 2) - 2016
link : Latest Android Studio Navigation Drawer Tutorial (Part 2) - 2016

Baca juga


Latest Android Studio Navigation Drawer Tutorial (Part 2) - 2016

Hello everyone, my name is Oum Saokosal.

This is part 2 of the navigation drawer, soI continued from the previous video about the basic of navigation drawer.

I talked about how to cross align some ofthe basic thing on the navigation drawer including the icon, color, menu, and add some fragmentsin there.

So now we go on to Part 2, we are going toadd some user and then put some event handler on that.

Okay, this is the navigation drawer, we couldclick on the camera, we can click on the gallery, the fragment is different now, okay, and evenwe can pass data by the new instance method and get the data back by the callback method.

Now we want to put some, may be, a buttoninto the camera fragment, so let's go to fragment camera here, so now i want to have two edittext and one button.

So you want to give some ID and then hintto the edit text and a button as well.

Double click on the edit text, and call itetEmail okay and this one is etPassword and this one maybe just okay.

Maybe you want to give a hint to the edittext.

So we will put the hint here “Enter Email”and “Enter Password”, okay.

So now you want to put some event on that,so maybe the bottom click for this fragment camera, so you go to CameraFragment.

Java here,as what i said in the previous lesson, the most important method is onCreateView, thisis the place where you want to add title views on that, so.

Now you want to declare and edit text outside,so… but this one is that you need to attach it to view instead of the raw one.

Now you want to declare EditText outside.

EditText etEmail, etPassword.

Button btnOK.

Here you can get it back as usual.

But when u call findViewById, there is nofindViewById here, but you can just call from the view, because view here inflate fragment,okay, so you can get the findViewById method of the view.

Now just like usual.

And the same to password.

So EditText view.

FindViewById(R.

Id.

EtPassword).

Lastly Button btnOK.

R.

Id.

BtnOK.

Then you can have the event here, okay.

So it is best to call the event handler callbackover here.

It is better to call like this in the fragmentand then you can have it close.

But note this, because I remember Toast inattached to the activities, not on the fragment.

So this here is not the real one because wewant to get the activity, just call CameraFragment.

This.

GetActivity.

So, you want to refer to the fragment becauseremember the fragment inflate to the, you know, like by the manager, remember that?here.

The main activity here.

you can have the FragmentManager, so it replacethe relative layout with the camera fragment, so the fragment now, it belong to the mainactivity.

Because of that you can call the this.

GetActivityinside the fragment.

Okay, so here is how you call the findViewByIdinside the fragment.

And you call the activity which is the context,something like this, okay.

ok Now you go to camera, okay.

You see? you go to Gallery here, somethingdifferent.

Let's say kosal, kosal, just for testing,nothing special here.

Now you want to compare if etEmail.

GetText().

ToString().

Equals().

String in Java, you cannot say double equal(==) like this.

You have to use the method equals(), ok? And then you can equal, let’s say “kosal”,ok.

And maybe the password too.

etPassword.

Let’s say correct.

else… incorrect.

just for testing, nothing special here.

Let’s say kosal, kosal, then correct.

If type something else, incorrect.

OK that’s all.

Now let’s change something in the gallery.

I want to add like ListView in the gallery,just an example, so I just want to do a different thing, different components.

Drag a ListView here.

So double click on it and change lvProductokay.

So, in the gallery fragment here, now youhave this, but actually you do not need anything like this, so you just, you know, don’tthink about it, but this one is the same thing, you have to call view and cut this code andreturn the view, okay.

So here you can add data into the ListView,so ListView need data and data need, you know, like a data and then the layout, so maybewe can create a class to hold the data.

So I call product.

So private String name; private int qty; privatedouble price; So I need a Constructor, so go to Code, go to Generate and then call Constructorhere.

So first I need the none one and second generateor the CTRL+N on Mac, and Constructor again, then check the three.

I need setters and getters.

This is the class for you, so go here andthen you need the ArrayList of product.

And I call product = new ArrayList.

So just add p1, new Product.

And maybe Coke 100 and 0.

5 integer.

[mumble] You just cut this, fine.

Now maybe you need some more.

If you want a lot of data, you can generatefrom for loop, okay, but that is not that important for now from example here.

Now, you add all the data into the ArrayListproduct, like this.

Then you need an Adapter, just use the simpleArrayAdapter.

it’s easy.

adapter = new ArrayAdapter.

And this one, you need ‘this’.

And I will change the list later.

The Second one, you need a resource becauseyou don’t have any resource.

Just use a default one from Android.

Use the simple_list_item_1.

And the last one is the data product.

And this one is the same thing, ok.

Now, you need the GalleryFragment.

This.

GetActivity().

And lastly you want to add to the ListView, soI call lvProduct like this.

view.

FindViewById(R.

Id.

LvProduct) here.

And lvProduct.

SetAdapter(adapter) done.

So, you run it.

As you can see now, you have a problem becausedata doesn’t do well because the simple list item just hold only one data, but youcan use a library from Fundater, but you can use a library from.

but you can use a libraryfrom Fundapter here.

Here you can just type Fundater, just go tothe github, you can see another video about this, but just an example of the navigationdrawer, just want to do the quick thing here.

Go to Gradle.

Add the Gradle here.

Sync.

So you need the internet to sync okay.

Okay, his library got one bug, so to fix thatyou go to Manifest, androidmanifest.

Actually it's not necessary to do until this,you know, you can just stop it because we know how to do that, but maybe you want toknow how to make a list and then make an array adapter easily.

So… if you want to learn more, if you wantto learn more, maybe you can just sit and watch, so need to add the namespace, CTRL+SPACEhere and this is the last one tools and here tools replace, okay, android:icon.

The problem is that in the library of his,he got icon, ic_launcher the same thing as ours.

So that is the problem.

So, now we need to sync, but maybe you needto run and if it is working then you can use this library.

Okay, looks good.

So now, we can continue, so for the ListView,you need a layout for that.

So… here you use the simple one which isnot correct, so we need to add a layout for the, you know, ListView item.

So if you go down in xml layout, xml fileand it is called product_layout, and you are free to change the layout to anything, maybeRelative is a good one.

okay, so maybe some text, and the medium one,and another medium one.

So the first one is tvName for the name andthis tvQty, tvPrice, okay.

Now you can use BindDictionary from the FunDapterlibrary to bind the data together, so… So this library is very flexible, you canadd, you know, like any data bind to another one of the text.

So I just need to add string field, so R.

Id.

TvName,the one that we just created and call new, Ctrl+Space, StringExtractor and then… youcan return the product.

product now is getName() ok.

So you do the same thing with the other three.

So you will change this, tvQty, ok.

getQty().

But this one is the String, i’m so sorry.

This one is the integer and you add the string, so just this, fine.

So the same thing to boolean, so the samething to double.

So now you don’t need the ArrayAdapter anymoreand use the Fundapter instead, okay, the one that we just got it from the github and Icall the adapter new Fundapter.

So “this” and then ArrayList, this isa product, and then resource layout.

So R.

Layout.

Product_layout here.

And the last one is the dictionary, but thisone we got a problem, because we need to call the gallery fragment like this, but getActivity,okay.

Then use the adapter to attach to the lvProduct,okay.

Gallery, see that? Okay, so now you got it correctly.

Maybe the last one I want to have an eventon the item, so just call lvProduct, set on item click listener, new CTRL+SPACE and ENTER.

OK, So here, you can grab the data, like youclick on that, you can grab the data off the product selected.

So to get that, you need to call the productand product has to be the final, you want to use the product inside the anonymous class,so product has to be final.

And then you can define an object, SelectedProduct,product.

Get(position).

So this is the position.

So position here is like 0, 1, 2, 3, 4, 5.

So when you click on, let’s say cocktail,so 0, 1, 2, 3.

So we will get the data of the position #3.

So if it is the cocktail, 300 and 2.

5, okay.

So, toast it.

Again this one will need to be GalleryFragment.

This.

GetActivity(),SelectedProduct.

GetName(), short, show, okay.

Okays lets go to Gallery again, now let’sclick on cocktail, see that? cocktail.

Ok, now you can just do anything with that.

Ok that's it for my video.

If you liked this, please don't forget tosubscribe and I will see you in the 3rd video.

Thank you.



Thus Article Latest Android Studio Navigation Drawer Tutorial (Part 2) - 2016

That article Latest Android Studio Navigation Drawer Tutorial (Part 2) - 2016 This time, hopefully we can give you all of the benefits. Well, I'll see you in another article post.

You now read the article Latest Android Studio Navigation Drawer Tutorial (Part 2) - 2016 the link address http://svedda79.blogspot.com/2016/11/latest-android-studio-navigation-drawer.html

0 Response to "Latest Android Studio Navigation Drawer Tutorial (Part 2) - 2016"

Post a Comment