Creating An Android App Source Code Final Of One Project Just Java App

XML FORMAT

<?xml version="2.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"
tools:context=".MainActivity">


<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="16dp" android:text="quantity" android:textAllCaps="true" />

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">

<Button android:id="@+id/button4" android:layout_width="48dp" android:layout_height="48dp" android:layout_marginLeft="16dp" android:layout_marginBottom="16dp" android:onClick="decrement" android:text="-" />

<TextView android:id="@+id/quantity_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="16dp" android:layout_marginLeft="8dp" android:text="0" android:textColor="#000000" android:textSize="16sp" />

<Button android:id="@+id/button3" android:layout_width="48dp" android:layout_height="48dp" android:layout_marginBottom="16dp" android:layout_marginLeft="8dp" android:layout_marginRight="16dp" android:onClick="increment" android:text="+" />

</LinearLayout>

<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="16dp" android:text="price" android:textAllCaps="true" />

<TextView android:id="@+id/price_text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginTop="16dp" android:text="$0" android:textColor="#000000" android:textSize="16sp" />

<Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginTop="16dp" android:onClick="submitOrder" android:text="order" android:textAllCaps="true" />

</LinearLayout>


JAVA CODE

 package com.example.android.justjava;

/** * IMPORTANT: Add your package below. Package name can be found in the project's AndroidManifest.xml file. * This is the package name our example uses: * <p>
* package com.example.android.justjava; */

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import java.text.NumberFormat;

/** * This app displays an order form to order coffee. */public class MainActivity extends AppCompatActivity {
int quantity = 0;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

/** * This method is called when the plus button is clicked. */ public void increment(View view) {

quantity = quantity + 1;
display(quantity);

/** * This method is called when the minus button is clicked. */ }
public void decrement(View view) {

quantity = quantity - 1;
display(quantity);



}
public void submitOrder(View view) {
int price = (quantity * 5);
String priceMessage = "Total: ₹" + price + "\n Thank You!" ;
displayMessage(priceMessage);

}


/** * This method displays the given price on the screen. */ private void displayPrice(int number) {
TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number));
}

/** * This method displays the given quantity value on the screen. */ private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
/** * This method displays the given text on the screen. */ private void displayMessage(String message) {
TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
priceTextView.setText(message);
}
}


SCREEN SHOT



Combining Strings Together Subtitles

When dealing with strings in Java, an important concept to understand is string concatenation. Now that's a really big word, but it just means we're joining character strings together end to end. If this is a string and this is a string, you can combine them by concatenating them to make an even longer string. To concatenate these strings together, we use the plus operator. This is the same addition symbol that we know from math. Just like you can add numbers together, you can concatenate strings together. Let's look at an example. Say I have three different strings, one string literal says I need, another string literal says 2 cups of coffee, and another string literal says on Monday. I can use the plus symbol to concatenate all these strings together. That forms a ginormous string that says I need2 cups of coffeeon Monday. Whenever I see something like this, I imagine the plus symbols are gone, and I imagine the quotes are gone, and I just imagine literally squishing all of these things together. And when I say squished, we're really squishing them together. There's even no extra space in between this string and this string. If you want to add a space here, you would have to explicitly add a space in this string literal at the end of it, or you add a space at the beginning of this string literal. Same with coffeeon Monday. I want a space here, so I'd have to either add it at the end of this string or the beginning of this string. I added a space here and a space here, so when I concatenate all of this together, I squish them together, and the sentence comes out correct like this. There's a space here and a space here. Adding spaces in the right place is a little bit tricky because you have the quotation marks everywhere and the plus symbols, and there's even spaces around the plus symbol. But these spaces around the plus symbol don't contribute to the overall display string. The space must be inside the double quotes. Here's an example of string concatenation in our app. I'm going to change the text so that it says "Amount due " + "$10". I'm concatenating this string literal with this string literal. When I run it on my device, and then I hit the order button, then I see Amount Due $10. You can also concatenate strings with integers like I have here. Before, the ten was in quotes so that was a string representation of the number ten. But here I just have 100 without quotes, so this is the integer value for 100. If I concatenate a string with an integer, then it immediately turns this whole thing into a string. If I hit the Order button, then I see $100 showing up on the screen. In a moment, I'll have you play around with string concatenation to try different values. You could get compile errors, so be careful of those. If I forget a closing quote, I could get an error. In a moment, I'll have you play around with string concatenation and try different values. According to Android code style guidelines, we should have a space before and after each operator. And this string concatenation operator counts as an operator. Now it's your turn to practice in your app. Experiment with combining different strings using the plus operator. You can also combine it with integer literal values as well. Once you feel comfortable with string concatenation, I want you to answer these questions.

Nested View Group

When discussing how to position views in the last quiz, you may have mentioned using a relative layout. I know we did. But I want to introduce you to another way that you can build the layout for our app that would be more ideal, using nested viewgroups.

Nested viewgroups means putting viewgroups inside other viewgroups. That way you can build more interesting and complex layouts like these. Let's see how you would build up one of these layouts. Say, for example, you have a vertical linear layout with three views, an image view and two text views. What if you wanted to overlay some text on top of this image? Well, with a linear layout, you can't overlap views. But with a relative layout, you can, so we can replace this child with a relative layout instead. Then, we can put the image view inside this relative layout. This image view is now aligned to each edge of the parent relative layout. So, there you see an example of a relative layout that's contained within a larger linear layout. You can have many combinations of view groups within other view groups. For instance, you can have a relative layout as a root view for an app. That can contain a couple of views like an image view and two text views. You can also add a linear layout as a child of this broader relative layout. This linear layout itself can contain other children like two image views. You can nest as many view groups inside other view groups as you want. However, be careful because the more nesting that you do, the more expensive it will be for your app to lay out on the screen. The relative layout, in particular, is a very flexible layout but it can be very complex to calculate the position of each of these views relative to others. So it's recommended to not have too many layers of nesting within a relative layout. I pulled some examples from real life Google apps to show you some cases where it would be useful to use nested view groups. The Google Now app shows you cards of relevant information based on your current situation, like the current time or current location. If you like a certain team like the Red Sox, good choice, then it can show you the score for the latest game. To build out the layout for this card, you can imagine using a vertical linear layout because the information is displayed as rows. However, the first item in this vertical linear layout is not just a single text view, it's made up of multiple views. In fact, you would build this first item as a horizontal linear layout, made up of an image view and two text views. Same for the second item in this vertical linear layout. You would build it with a horizontal linear layout containing an image view and two text views.

 Another card in the Google Now app shows relevant stocks that you may be interested in. I wish the Google stock was still at that price. Anyways, you can also build out this layout as a vertical linear layout, because you can imagine the rows here. Except these middle entries aren't just a single text view, they're made up of multiple text views. For this line item relating to the Google stock price, you could use a horizontal linear layout and fill it with four text views. Same for the other stock prices as well. These horizontal linear layouts are children of this broader vertical linear layout. In the Google Play music app, you can, of course, listen to music.

 While this looks like a complicated layout to build, you can actually break it down into smaller view groups that you recognize. This pattern feels like a vertical linear layout with three different children. This first child can be built using a relative layout, because the views are relative to each other. The second child can also be built using a relative layout, because the views are overlapping each other. And this third child here looks like a horizontal linear layout made up of five different buttons. Again, we can use nested view groups to build out this screen. This is just one way to build out the layout. You can build it in many other ways as well. In the Google Maps app, earlier we saw that there are detailed pages for individual locations, like restaurants.

 You can't build out this screen with just a single linear layout or a single relative layout. You need to nest a bunch of view groups together. On a broad scale, we can see that the information is almost organized into rows. So, we can use a vertical linear layout as the parent view. One child could be this whole layout here. Another child could be this row of buttons. Another child would be this description and so on. But within each child is not just a single view. We have multiple views. This child in the broader linear layout is made up of three individual views. So you can use a horizontal linear layout with equal weights to each view so that they get spread out evenly. This child in the broader vertical linear layout can also be made up of a horizontal linear layout with an image view and a text view. If you keep scrolling this page, you see more information on the restaurant. Again, I can imagine the individual rows of information here. Using a vertical linear layout for all this information still works, and, again, some rows are more complex than just a single text view. This row shows a bunch of available times where you can make a reservation, and it's made up of three different buttons that you can arrange using a horizontal linear layout. This row of pictures can be built using a horizontal linear layout as well. And actually, within this horizontal linear layout, this first child is not just a single image view. It's an image view with a text view. So you could use a relative layout to build out this first child. So you could see how there can be view groups, within view groups, within view groups. There's actually more view groups beyond just relative layout, and linear layout, there's also frame layout and grid layout. We're not going to have time to cover those in this course, but I definitely recommend that you go out and learn about them on your own because sometimes those would be better than just using a relative or a linear layout.

కరోనా కోవిడ్ -19 గురించి ఏ వికీపీడియా మీకు చెప్పలేము?

కరోనా కోవిడ్ -19 గురించి ఏ వికీపీడియా మీకు చెప్పలేము? మిమ్మల్ని మీరు రక్షించుకోండి  Your మీ చేతులను తరచుగా కడగాలి Eyes మీ కళ్ళు, న...