Tuesday, August 30, 2016
Thursday, August 25, 2016
Abstract Class C#
An Abstract class is a class with incomplete functionality.
It shall or shall not have abstract methods. As in the case with Interface you can't create an object of Abstract class.
It shall or shall not have abstract methods. As in the case with Interface you can't create an object of Abstract class.
abstract class Person
{
public abstract void Print();
public void Blog()
{
Console.WriteLine("ShalvinPD.blogspot.com");
}
}
class Shalvin : Person
{
public override void Print()
{
Console.WriteLine("Shalvin P D");
}
}
class Program
{
static void Main(string[] args)
{
//Error cannot create an object of Abstract Class
//Person p = new Person();
Shalvin s = new Shalvin();
s.Print();
s.Blog();
Console.ReadLine();
}
}
Here I am having an Abstract class called person with an abstract method called Print and an ordinary method called blog. In the sub class I am overriding the abstract Print method.
Method overriding C#
class Person
{
public virtual void Print()
{
Console.WriteLine("Hello Person");
}
}
class Shalvin : Person
{
public override void Print()
{
Console.WriteLine("Hello Shalvin");
}
}
class ShalvinPD : Shalvin
{
}
class Reshma : Person
{
public override void Print()
{
Console.WriteLine("Hello Reshma");
}
}
class Program
{
static void Main(string[] args)
{
Person p = new Person();
p.Print();
Shalvin s = new Shalvin();
s.Print();
ShalvinPD spd = new ShalvinPD();
spd.Print();
Reshma r = new Reshma();
r.Print();
Console.ReadLine();
}
}
}
Sunday, June 26, 2016
Android SQLite Database Connnectivity
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void btnAddClick(View view) {
EditText editText = (EditText)findViewById(R.id.etName);
String strExpense = editText.getText().toString();
SQLiteDatabase sqLiteDatabase = openOrCreateDatabase("ExpenseDB", MODE_PRIVATE, null);
String create = "CREATE Table IF NOT EXISTS Expenses (ExpenseId integer primary key autoincrement, ExpenseName varchar(40));";
sqLiteDatabase.execSQL(create);
String insert = "INSERT INTO Expenses (ExpenseName) values ('" + strExpense + "');";
sqLiteDatabase.execSQL(insert);
Toast.makeText(MainActivity.this, "Record Saved", Toast.LENGTH_SHORT).show();
editText.setText("");
}
public void btnShowClick(View view) {
SQLiteDatabase sqLiteDatabase = openOrCreateDatabase("ExpenseDB", MODE_PRIVATE, null);
String strSelect = "select * from Expenses;";
Cursor cursor = sqLiteDatabase.rawQuery(strSelect, null);
TextView textView = (TextView)findViewById(R.id.tvExpense);
if(cursor.getCount() > 0)
{
cursor.moveToFirst();
do {
String expense = cursor.getString(1);
textView.setText(textView.getText() + "\n" + expense);
}while (cursor.moveToNext());
}
}
}
Android WebView
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://shalvinpd.blogspot.com");
}
Saturday, June 25, 2016
Android Style
colors.xml
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorYellow">#FFFF00</color>
</resources>
styles.xml
<style name="buttonStyle">
<item name="android:background">@color/colorYellow</item>
</style>
<Button
style="@style/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:id="@+id/button"
android:layout_centerVertical="true"
android:layout_alignParentStart="true" />
Friday, June 24, 2016
Android LinearLayout weight_sum and weight properties
<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="com.blogspot.shalvinpd.linearlayouteg.MainActivity"
android:weightSum="2">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="Hello World!"
android:background="@color/colorPrimary"/>
<TextView
android:layout_width="match_parent"
android:background="@color/colorAccent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Hello World!" />
</LinearLayout>
Subscribe to:
Posts (Atom)

