Friday, 15 February 2019

TextView in Android

In Android, TextView displays text to the user and optionally allows them to edit it programmatically.
TextView is a complete text editor, however basic class is configured to not allow editing but we can edit it.


View is the parent class of TextView. Being a subclass of view the text view component can be used in your app’s
GUI inside a ViewGroup, or as the content view of an activity.
We can create a TextView instance by declaring it inside a layout(XML file) or by instantiating
it programmatically(Java Class).
TextView code in XML:

<TextView android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PirawenAndroid" />
TextView code in JAVA:

TextView textView = (TextView) findViewById(R.id.textView);

textView.setText("PirawenAndroid"); //set text for text view


Attributes of TextView:
Now let’s we discuss about the attributes that helps us to configure a TextView in your xml file.
1. id: id is an attribute used to uniquely identify a text view. Below is the example code in which we set
the id of a text view.
<TextView
android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

2. gravity: The gravity attribute is an optional attribute which is used to control the alignment of the
text like left, right, center, top, bottom, center_vertical, center_horizontal etc.
Below is the example code with explanation included in which we set the center_horizontal gravity for text
of a TextView.
<TextView
android:id="@+id/simpleTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="PirawenAndroid"
android:textSize="20sp"
android:gravity="center_horizontal"/> <!--center horizontal gravity-->

3. text: text attribute is used to set the text in a text view. We can set the text in xml as well as in the java class.
Below is the example code with explanation included in which we set the text “PirawenAndroid” in a text view.

<TextView
android:id="@+id/simpleTextView"

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="25sp"
android:text="PirawenAndroid"/><!--Display Text as PirawenAndroid-->
In Java class:
Below is the example code in which we set the text in a textview programmatically means in java class.
TextView textView = (TextView)findViewById(R.id.textView);
textView.setText("PirawenAndroid"); //set text for text view
4. textColor: textColor attribute is used to set the text color of a text view.
Color value is in the form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.
Below is the example code with explanation included in which we set the red color for the displayed text.
<TextView
android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PirawenAndroid"
android:layout_centerInParent="true"
android:textSize="25sp"
android:textColor="#f00"/><!--red color for text view-->


In Java class:
Below is the example code in which we set the text in a textview programmatically means in java class.
TextView textView = (TextView)findViewById(R.id.textView);
textView.setText("PirawenAndroid"); //set text for text view
4. textColor: textColor attribute is used to set the text color of a text view.
Color value is in the form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.
Below is the example code with explanation included in which we set the red color for the displayed text.
<TextView
android:id="@+id/simpleTextView"
android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="PirawenAndroid"
android:layout_centerInParent="true"
android:textSize="25sp"
android:textColor="#f00"/><!--red color for text view-->

In Java class:
Below is the example code in which we set the text size of a text view programmatically means in java class.
TextView textView = (TextView)findViewById(R.id.textView);
textView.setTextSize(20); //set 20sp size of text

6. textStyle: textStyle attribute is used to set the text style of a text view.
The possible text styles are bold, italic and normal.  If we need to use two or more styles for a text view then
“|” operator is used for that.
Below is the example code with explanation included in which we  set the bold and italic text styles for text.

<TextView
   android:id="@+id/simpleTextView"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="PirawenAndroid"
   android:layout_centerInParent="true"
   android:textSize="40sp"
   android:textStyle="bold|italic"/><!--bold and italic text style of text-->
7. background: background attribute is used to set the background of a text view.
We can set a color or a drawable in the background of a text view.
8. padding: padding attribute is used to set the padding from left, right, top or bottom.
In above example code of background we also set the 10dp padding from all the side’s of text view.
Below is the example code with explanation included in which we set the black color for the background,
white color for the displayed text and set 10dp padding from all the side’s for text view.
<TextView
android:id="@+id/simpleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PirawenAndroid"
android:layout_centerInParent="true"
android:textSize="40sp"
android:padding="10dp"
android:textColor="#fff"
android:background="#000"/> <!--red color for background of text view-->
In Java class:
Below is the example code in which we set the background color of a text view programmatically means in
java class.
TextView textView = (TextView)findViewById(R.id.textView);
textView.setBackgroundColor(Color.BLACK);//set background color

Example of TextView:
Below is the example of TextView in which we display a text view and set the text in xml file and then change
the text on button click event programmatically. Below is the final output and code:
Step 1: Create a new project and name it textViewExample.

Select File -> New -> New Project. Fill the forms and click "Finish" button.
Step 2: Open res -> layout -> xml (or) activity_main.xml and add following code.
Here we will create a button and a textview in Relative Layout.

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
   android:paddingLeft="@dimen/activity_horizontal_margin"
   android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
   tools:context=".MainActivity">

   <TextView
       android:id="@+id/simpleTextView"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_centerHorizontal="true"
       android:text="Before Clicking"
       android:textColor="#f00"
       android:textSize="25sp"
       android:textStyle="bold|italic"
       android:layout_marginTop="50dp"/>

   <Button
       android:id="@+id/btnChangeText"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_centerInParent="true"

       android:background="#f00"
       android:padding="10dp"
       android:text="Change Text"
       android:textColor="#fff"
       android:textStyle="bold" />
</RelativeLayout>


Step 3: Open app -> java -> package and open MainActivity.java and add the following code.
Here we will change the text of TextView after the user click on Button.

package example.irawen.textviewexample;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main); //set the layout

       final TextView simpleTextView = (TextView) findViewById(R.id.simpleTextView);

//get the id for TextView

       Button changeText = (Button) findViewById(R.id.btnChangeText); //get the id for button

       changeText.setOnClickListener(new View.OnClickListener() {
           @Override

           public void onClick(View view) {
               simpleTextView.setText("After Clicking"); //set the text after clicking button

           }
       });
   }


}

Output:
Now run the app in Emulator and click on the button. You will see text will change “After Clicking”.
 

First Program in Python

Open your favorite text editor and type the following program.

Python Code :
def printMessage( ):
  print("The Quick Brown Fox Jumps Over The Lazy Dog!")
if_name_=="_main_":
printMessage( )

Let us look at the program line by line to understand what it is doing.

Python Code :
def printMessage( ):
  print("The Quick Brown Fox Jumps Over The Lazy Dog!")

The above line is a function in Python.The function is printing a message to the screen.

Python Code :
if_name_=="_name_":

The above line checks if the module is running as main.
When python runs the module, it sets _name_variable to the value_main_.
Main check is the entry point for a Python Program.

Python Code:
printMessage( )

The above line is a function call in Python.
The function call printMessage was defined above.

We can call function defined in other modules by importing them.We can use import keyword to import other functions.Similarly other modules can import printMessage function by importing from our file.

We can save the file to a favorite location. 
Name the file: HelloWorld.py. We can run the file using the following command .

Command:
python HelloWorld.py

Output:
The Quick Brown Fox Jumps Over The Lazy Dog!

Thursday, 14 February 2019

Range and Xrange in Python

Range function in Python can be used to generate a range of values.

Example if we call range(10), we will get values 0 to 10 in a list.

If we call range (1,11), we will get values 1 to 10 in a list.

Let us look at a few examples to understand better.

Python Code :
range(5)

Output :
[1,2,3,4]

Python Code :
range(2,7)

Output :
[2.3,4,5,6]

Python Code :
range(1, 10, 2)

Output:
[1,3,5,7,9]

In above example, we only printed odd numbers. We could do that by passing a third increment parameter to range.

xrange function is similar to range function. But it is very efficient for large sets.When range is invoked, it creates a static list and returns the result.

However with xrange, it gives a pointer and only gives the next value on demand when iterating over the list. This can prevent out of memory errors.

Python Code :
list(xrange(5))

Output :
[1,2,3,4]

Monday, 11 February 2019

Programming with C++ Book

Programming with C++ 

The book is intended to provide an introduction to Programming with C++. In keeping with the basic approach of all schaums series books, this book aims to help the students develop their problem solving skills. The plethora of solved examples and practice questions in the book enables the stiudents to get a intutive grasp on the subject.

Programming with C++ 

 Programming with C++

Object-Oriented Programming with C++

Object-Oriented Programming with C++ 

The book aims at providing an all-round enrichment of knowledge in the area of object-oriented programming with C++ as the implementation of language. The author has used simple language to explain critical concepts of object-oriented programming and for better understanding of the readers. The same concepts have been implemented in solved examples using C++ programming language. 
 Object-Oriented Programming with C++

Object-Oriented Programming with C++ 
 
Retaining is original style of lucid writing, the books has ample solved examples, programming exercises and new practice questions. This revised edition has new projects and incorporates a couple of new elements like Learning Objectives and Limitations. The topic on Polymorphism has been revised and expanded for better understanding.
Object-Oriented Programming with C++ 

Learn R in a Day Kindle Edition

Learn R in a Day

'Learn R in a Day' provides the reader with key programming skills through an examples-oriented approach and is ideally suited for academics, scientists, mathematicians and engineers. The book assumes no prior knowledge of computer programming and progressively covers all the essential steps needed to become confident and proficient in using R within a day. 

Learn R in a Day


 Learn R in a Day
Topics include how to input, manipulate, format, iterate (loop), query, perform basic statistics on, and plot data, via a step-by-step technique and demonstrations using in-built datasets which the reader is encouraged to replicate on their computer. Each chapter also includes exercises (with solutions) to practice key skills and empower the reader to build on the essentials gained during this introductory course.
Learn R in a Day  

Saturday, 9 February 2019

Deep Learning with Python by Francois Chollet

Deep learning is applicable to a widening range of artificial
intelligence problems, such as image classification, speech recognition,
text classification, question answering, text-to-speech, and optical
character recognition.

Deep Learning with Python is structured around a series of practical
code examples that illustrate each new concept introduced and
demonstrate best practices. By the time you reach the end of this book,
you will have become a Keras expert and will be able to apply deep
learning in your own projects.

KEY FEATURES

• Practical code examples
• In-depth introduction to Keras
• Teaches the difference between Deep Learning and AI

ABOUT THE TECHNOLOGY
Deep learning is the technology behind photo tagging systems at
Facebook and Google, self-driving cars, speech recognition systems on
your smartphone, and much more.

AUTHOR BIO
Francois Chollet is the author of Keras, one of the most widely used
libraries for deep learning in Python. He has been working with deep neural
networks since 2012. Francois is currently doing deep learning research at
Google. He blogs about deep learning at blog.keras.io.

Buy:Deep Learning with Python Paperback – Import, 30 Nov 2017 by Francois Chollet (Author)

Pdf download:Deep Learning with Python

The Quick Python Book by Naomi R Ceder

Buy: The Quick Python Book, 3E Paperback – Import, 31 May 2018 by Naomi R Ceder (Author)

Pdf download: The Quick Python Book, 3E

Numerical Python by Robert Johansson

Numerical Python by Robert Johansson shows you how to leverage the numerical and mathematical modules in Python and its Standard Library as well as popular open source numerical Python packages like NumPy, FiPy, matplotlib and more to numerically compute solutions and mathematically model applications in a number of areas like big data, cloud computing, financial engineering, business management and more. 

After reading and using this book, you'll get some takeaway case study examples of applications that can be found in areas like business management, big data/cloud computing, financial engineering (i.e., options trading investment alternatives), and even games. Up until very recently, Python was mostly regarded as just a web scripting language. Well, computational scientists and engineers have recently discovered the flexibility and power of Python to do more. Big data analytics and cloud computing programmers are seeing Python's immense use. 

Financial engineers are also now employing Python in their work. Python seems to be evolving as a language that can even rival C++, Fortran, and Pascal/Delphi for numerical and mathematical computations.

Pdf Download:


Python Continuous Integration and Delivery: A Concise Guide with Examples by Moritz Lenz

Gain the techniques and tools that enable a smooth and efficient software development process in this quick and practical guide on Python continuous integration (CI) and continuous delivery (CD). Based on example applications, this book introduces various kinds of testing and shows you how to set up automated systems that run these tests, and install applications in different environments in controlled ways. Python Continuous Integration and Delivery tackles the technical problems related to software development that are typically glossed over in pure programming texts.

After reading this book, you’ll see that in today's fast-moving world, no software project can afford to go through development, then an integration phase of unpredictable length and complexity, and finally be shipped to the customer -- just to find out that the resulting application didn't quite fill their need. Instead, you’ll discover that practicing continuous integration and continuous delivery reduces the risks by keeping changes small and automating otherwise painful processes.

What You Will Learn
  • Carry out various kinds of testing, including unit testing and continuous integration testing, of your Python code using Jenkins

  • Build packages and manage repositories

  • Incorporate Ansible and Go for automated packaging and other deployments

  • Manage more complex and robust deployments
Who This Book Is For
Python programmers and operating staff that work with Python applications.

Buy:Python Continuous Integration and Delivery: A Concise Guide with Examples Kindle Edition by Moritz Lenz (Author)

PDF Download:
Python Continuous Integration and Delivery: A Concise Guide with Examples

Wednesday, 6 February 2019

R language by Michael J. Crawley


R language by Michael J. Crawley 
 
The R language is recognized as one of the most powerful and flexible statistical software packages and it enables the user to apply many statistical techniques that would be impossible without such software to help implement such large data sets. R is becoming essential both to carry out research and to understand it, as more and more people present their results in the context of R. This edition introduces the advantages of the R environment, in a user-friendly format, to beginners and intermediate users in a range of disciplines, from science and engineering to medicine and economics. The format enables it to be either read as a text, or dipped-into as a reference manual.
 
R language by Michael J. Crawley 

Popular Posts

Categories

100 Python Programs for Beginner (13) AI (33) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (161) C (77) C# (12) C++ (82) Course (67) Coursera (223) Cybersecurity (24) data management (11) Data Science (127) Data Strucures (8) Deep Learning (20) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (34) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (53) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (1) Pandas (3) PHP (20) Projects (29) Python (917) Python Coding Challenge (304) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (42) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses