You are on page 1of 22

package com.example.

gpsbustracker;
import android.support.v7.app.ActionBarActivity;

import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

android.app.Activity;
android.database.Cursor;
android.database.sqlite.SQLiteDatabase;
android.graphics.Color;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.view.ViewGroup;
android.view.ViewGroup.LayoutParams;
android.widget.Button;
android.widget.ScrollView;
android.widget.TableLayout;
android.widget.TableRow;
android.widget.TextView;
android.widget.Toast;

public class ViewRecords extends ActionBarActivity {


Button b1;
TextView t1;
TableLayout tl1;
ScrollView sv;
SQLiteDatabase mydb=null;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_records);
//
b1=(Button)findViewById(R.id.btnBack);
//t1=(TextView)findViewById(R.id.txtResult);
myListener2 m=new myListener2();
//
b1.setOnClickListener((OnClickListener) m);
tl1 = (TableLayout)findViewById(R.id.myTableLayout);
//t1=(TextView)findViewById(R.id.textView1);
sv = (ScrollView)findViewById(R.id.scrollView901);
mydb=openOrCreateDatabase(cls.dbname,MODE_PRIVATE ,null)
;
Cursor c=null;
if(cls.viewtype==1)
{
c=mydb.rawQuery("Select * From Booking",null);
//Toast.makeText(ViewRecords.this, "Blood", Toas
t.LENGTH_LONG).show();
}
else if(cls.viewtype==2)
c=mydb.rawQuery("Select * From Booking",null);
else if(cls.viewtype==3)
c=mydb.rawQuery("Select * From Booking",null);
else if(cls.viewtype==4)
c=mydb.rawQuery("Select * From Booking",null);
c.moveToFirst();

StringBuilder sb1=new StringBuilder();


String Sc;
TableRow tr1 = new TableRow(this);
TextView b11 = new TextView(this);
if(cls.viewtype==1)
b11.setText("Booking");
else if(cls.viewtype==2)
b11.setText("Sand Details");
else if(cls.viewtype==3)
b11.setText("Brick Details");
else if(cls.viewtype==4)
b11.setText("Steel Rod Details");
tr1.addView(b11);
tl1.addView(tr1,new TableLayout.LayoutParams(LayoutParams.FILL
_PARENT,LayoutParams.FILL_PARENT));
tr1.setBackgroundColor(Color.BLUE);
//
TableRow tr11 = new TableRow(this);
// TextView b12 = new TextView(this);
// b12.setText("Records List");
// tr11.addView(b12);
// tl1.addView(tr11,new TableLayout.LayoutParams(LayoutParams.F
ILL_PARENT,LayoutParams.FILL_PARENT));
// tr11.setBackgroundColor(Color.GREEN);
TableRow trheader = new TableRow(this);
TextView bheader = new TextView(this);
tl1.addView(trheader,new TableLayout.LayoutParams(LayoutParams
.FILL_PARENT,LayoutParams.FILL_PARENT));
trheader.setBackgroundColor(Color.WHITE);
if(cls.viewtype==1)
bheader.setText("Booking");
else if(cls.viewtype==2)
bheader.setText("Sand");
else if(cls.viewtype==3)
{
bheader.setText("Brick");
}
else if(cls.viewtype==6)
{
bheader.setText("Steel Rod");
}
int rowcount=0;

c.close();
//t1.setText(sb1.toString());
c=mydb.rawQuery("Select * From Booking",null);
c.moveToFirst();
while (c.isAfterLast()==false)
{
//

Sc=c.getString(0);
Toast.makeText(ViewRecords.this, Sc, Toast.LENGT

H_LONG).show();
//

sb1.append(Sc+"\r\n");// + "\t" + c.getSt

ring(1) + "\t" + c.getString(2);


//
TableRow tr = new TableRow(this);
tr.setLayoutParams(new ViewGroup.LayoutParams(ViewG
roup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT));
TextView b1 = new TextView(this);
// b1.setText("Booking");
// b1.setLayoutParams(new ViewGroup.LayoutParam
s(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
// tr.addView(b1);
TableRow tr2 = new TableRow(this);
TextView b121 = new TextView(this);
b121.setText(Sc);
// tr2.addView(b121);
//
tl1.addView(tr,new TableLayout.LayoutParams
(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//
tl1.addView(tr2,new TableLayout.LayoutParam
s(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
if(rowcount%2==0)
{
// tr.setBackgroundColor(Color.BLUE);
// b1.setTextColor(Color.WHITE);
}
else
{
//

tr.setBackgroundColor(Color.GREEN);

}
rowcount++;
c.moveToNext();
}
c.close();
c=mydb.rawQuery("Select * From Booking",null);
c.moveToFirst();
while (c.isAfterLast()==false)
{
Sc=c.getString(0);
//Toast.makeText(ViewRecords.this, Sc, Toast.LEN
GTH_LONG).show();
sb1.append("Brick:" + Sc+"\r\n");// + "\t"
+ c.getString(1) + "\t" + c.getString(2);
//
TableRow tr = new TableRow(this);
TextView b1 = new TextView(this);
b1.setText("Booking");
tr.addView(b1);
TableRow tr2 = new TableRow(this);
TextView b121 = new TextView(this);
b121.setText("Route:"+Sc +",Mobile:" + c.getSt
ring(1) + ",Date:"+c.getString(2)+ ",Seat:"+c.getString(3));
tr2.addView(b121);

tl1.addView(tr,new TableLayout.LayoutParams(L
ayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
tl1.addView(tr2,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
if(rowcount%2==0)
{
tr.setBackgroundColor(Color.BLUE);
b1.setTextColor(Color.WHITE);
}
else
{
tr.setBackgroundColor(Color.GREEN);
}
rowcount++;
c.moveToNext();
}
c.close();
c=mydb.rawQuery("Select * From Booking",null);
c.moveToFirst();
while (c.isAfterLast()==false)
{
Sc=c.getString(0);
Toast.makeText(ViewRecords.this, Sc, Toast.LENGT
H_LONG).show();
sb1.append("SteelRod:" + Sc+"\r\n");// + "\
t" + c.getString(1) + "\t" + c.getString(2);
//
// TableRow tr = new TableRow(this);
// TextView b1 = new TextView(this);
// b1.setText("SteelRod");
//
tr.addView(b1);
TableRow tr2 = new TableRow(this);
TextView b121 = new TextView(this);
b121.setText(Sc);
tr2.addView(b121);
// tl1.addView(tr,new TableLayout.LayoutParams
(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
tl1.addView(tr2,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
if(rowcount%2==0)
{
//
tr.setBackgroundColor(Color.BLUE);
//
b1.setTextColor(Color.WHITE);
}
else
{
//

tr.setBackgroundColor(Color.GREEN);
}
rowcount++;
c.moveToNext();

c.close();

mydb.close();
/*Cursor cr=
mydb.rawQuery("Select * From Subjects",null);
cr.moveToFirst();
StringBuilder sb=new StringBuilder();
while( cr.isAfterLast()==false)
{
sb.append(cr.getString(0) +"\t" + cr.getString(1) +"\t" + cr.get
String(2) +"\r\n");
cr.moveToNext();
}
cr.close();*/
//t1.setText(sb.toString());
//mydb.close();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar i
f it is present.
getMenuInflater().inflate(R.menu.view_records, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar wi
ll
// automatically handle clicks on the Home/Up button, so
long
// as you specify a parent activity in AndroidManifest.x
ml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
class myListener2 implements View.OnClickListener
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
//case R.id.btnSave:
//String s1=t1.getText().toString();
//

mydb.execSQL("Delete From Subjects Where Subject

Code='" + s1 + "'");
//
mydb.execSQL("Insert into Subjects Values('" + s
1 + "','" + s2 + "','" + s3 + "')");
//Toast.makeText(AddSubject.this, "Subject Details Saved", Toast
.LENGTH_LONG).show();

//break;
//case R.id.btnBack:
//
finish();
//
break;
}
}
}
}
********************************************************************************
*************************************
package com.example.gpsbustracker;
import android.support.v7.app.ActionBarActivity;

import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

android.app.Activity;
android.database.Cursor;
android.database.sqlite.SQLiteDatabase;
android.graphics.Color;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.view.ViewGroup;
android.view.ViewGroup.LayoutParams;
android.widget.Button;
android.widget.ScrollView;
android.widget.TableLayout;
android.widget.TableRow;
android.widget.TextView;
android.widget.Toast;

public class ViewRecords extends ActionBarActivity {


Button b1;
TextView t1;
TableLayout tl1;
ScrollView sv;
SQLiteDatabase mydb=null;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_records);
//
b1=(Button)findViewById(R.id.btnBack);
//t1=(TextView)findViewById(R.id.txtResult);
myListener2 m=new myListener2();
//
b1.setOnClickListener((OnClickListener) m);
tl1 = (TableLayout)findViewById(R.id.myTableLayout);
//t1=(TextView)findViewById(R.id.textView1);
sv = (ScrollView)findViewById(R.id.scrollView901);
mydb=openOrCreateDatabase(cls.dbname,MODE_PRIVATE ,null)
;
Cursor c=null;
if(cls.viewtype==1)
{
c=mydb.rawQuery("Select * From Booking",null);

//Toast.makeText(ViewRecords.this, "Blood", Toas


t.LENGTH_LONG).show();
}
else if(cls.viewtype==2)
c=mydb.rawQuery("Select * From Booking",null);
else if(cls.viewtype==3)
c=mydb.rawQuery("Select * From Booking",null);
else if(cls.viewtype==4)
c=mydb.rawQuery("Select * From Booking",null);
c.moveToFirst();
StringBuilder sb1=new StringBuilder();
String Sc;
// TableRow tr1 = new TableRow(this);
// TextView b11 = new TextView(this);
//if(cls.viewtype==1)
//b11.setText("Booking");
//else if(cls.viewtype==2)
// b11.setText("Sand Details");
//else if(cls.viewtype==3)
// b11.setText("Brick Details");
// else if(cls.viewtype==4)
// b11.setText("Steel Rod Details");
//tr1.addView(b11);
// tl1.addView(tr1,new TableLayout.LayoutParams(LayoutParams.FI
LL_PARENT,LayoutParams.FILL_PARENT));
// tr1.setBackgroundColor(Color.BLUE);
//
TableRow tr11 = new TableRow(this);
// TextView b12 = new TextView(this);
// b12.setText("Records List");
// tr11.addView(b12);
// tl1.addView(tr11,new TableLayout.LayoutParams(LayoutParams.F
ILL_PARENT,LayoutParams.FILL_PARENT));
// tr11.setBackgroundColor(Color.GREEN);
// TableRow trheader = new TableRow(this);
//
TextView bheader = new TextView(this);
//
tl1.addView(trheader,new TableLayout.LayoutParams(LayoutPara
ms.FILL_PARENT,LayoutParams.FILL_PARENT));
// trheader.setBackgroundColor(Color.WHITE);
//
//
//
//
//

if(cls.viewtype==1)
bheader.setText("Booking");
else if(cls.viewtype==2)
bheader.setText("Sand");
else if(cls.viewtype==3)
// {
// bheader.setText("Brick");
//}
//else if(cls.viewtype==6)
//{
//bheader.setText("Steel Rod");
//}
int rowcount=0;

c.close();

//t1.setText(sb1.toString());
//
//

c=mydb.rawQuery("Select * From Booking",null);


c.moveToFirst();
//while (c.isAfterLast()==false)
{
//
//

Sc=c.getString(0);
Toast.makeText(ViewRecords.this, Sc, Toast.LENGT

H_LONG).show();
//
sb1.append(Sc+"\r\n");// + "\t" + c.getSt
ring(1) + "\t" + c.getString(2);
//
//
TableRow tr = new TableRow(this);
//
tr.setLayoutParams(new ViewGroup.LayoutParams(Vie
wGroup.LayoutParams.FILL_PARENT,
//
ViewGroup.LayoutParams.FILL_PARENT));
//
TextView b1 = new TextView(this);
// b1.setText("Booking");
// b1.setLayoutParams(new ViewGroup.LayoutParam
s(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
// tr.addView(b1);
//

TableRow tr2 = new TableRow(this);


// TextView b121 = new TextView(this);
// b121.setText(Sc);
// tr2.addView(b121);

//
tl1.addView(tr,new TableLayout.LayoutParams
(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//
tl1.addView(tr2,new TableLayout.LayoutParam
s(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//
if(rowcount%2==0)
//
{
// tr.setBackgroundColor(Color.BLUE);
// b1.setTextColor(Color.WHITE);
//
//
//
//
//
//
//

}
else
{
//

tr.setBackgroundColor(Color.GREEN);

}
rowcount++;
c.moveToNext();

}
c.close();
c=mydb.rawQuery("Select * From Booking",null);
c.moveToFirst();
while (c.isAfterLast()==false)

{
Sc=c.getString(0);
//Toast.makeText(ViewRecords.this, Sc, Toast.LEN
GTH_LONG).show();
sb1.append("Brick:" + Sc+"\r\n");// + "\t"
+ c.getString(1) + "\t" + c.getString(2);
//
TableRow tr = new TableRow(this);

TextView b1 = new TextView(this);


b1.setText("Booking");
tr.addView(b1);
TableRow tr2 = new TableRow(this);
TextView b121 = new TextView(this);
b121.setText("Route:"+Sc +",Mobile:" + c.getSt
ring(1) + ",Date:"+c.getString(2)+ ",Seat:"+c.getString(3));
tr2.addView(b121);
tl1.addView(tr,new TableLayout.LayoutParams(L
ayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
tl1.addView(tr2,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
if(rowcount%2==0)
{
tr.setBackgroundColor(Color.BLUE);
b1.setTextColor(Color.WHITE);
}
else
{
tr.setBackgroundColor(Color.GREEN);
}
rowcount++;
c.moveToNext();
}
c.close();
c=mydb.rawQuery("Select * From Booking",null);
c.moveToFirst();
while (c.isAfterLast()==false)
{
Sc=c.getString(0);
Toast.makeText(ViewRecords.this, Sc, Toast.LENGT
H_LONG).show();
sb1.append("SteelRod:" + Sc+"\r\n");// + "\
t" + c.getString(1) + "\t" + c.getString(2);
//
// TableRow tr = new TableRow(this);
// TextView b1 = new TextView(this);
// b1.setText("SteelRod");
//
tr.addView(b1);
TableRow tr2 = new TableRow(this);
TextView b121 = new TextView(this);
b121.setText(Sc);
tr2.addView(b121);
// tl1.addView(tr,new TableLayout.LayoutParams
(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
tl1.addView(tr2,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
if(rowcount%2==0)
{
//
tr.setBackgroundColor(Color.BLUE);

//

b1.setTextColor(Color.WHITE);
}
else
{

//

tr.setBackgroundColor(Color.GREEN);
}
rowcount++;
c.moveToNext();

}
c.close();

mydb.close();
}
/*Cursor cr=
mydb.rawQuery("Select * From Subjects",null);
cr.moveToFirst();
StringBuilder sb=new StringBuilder();
while( cr.isAfterLast()==false)
{
sb.append(cr.getString(0) +"\t" + cr.getString(1) +"\t" + cr.get
String(2) +"\r\n");
cr.moveToNext();
}
cr.close();*/
//t1.setText(sb.toString());
//mydb.close();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar i
f it is present.
getMenuInflater().inflate(R.menu.view_records, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar wi
ll
// automatically handle clicks on the Home/Up button, so
long
// as you specify a parent activity in AndroidManifest.x
ml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
class myListener2 implements View.OnClickListener
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub

switch(v.getId())
{
//case R.id.btnSave:
//String s1=t1.getText().toString();
//

mydb.execSQL("Delete From Subjects Where Subject

Code='" + s1 + "'");
//
mydb.execSQL("Insert into Subjects Values('" + s
1 + "','" + s2 + "','" + s3 + "')");
//Toast.makeText(AddSubject.this, "Subject Details Saved", Toast
.LENGTH_LONG).show();
//break;
//case R.id.btnBack:
//
finish();
//
break;
}
}
}
}
********************************************************************************
*****************************
package com.example.gpsbustracker;
import android.support.v7.app.ActionBarActivity;

import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

android.app.Activity;
android.database.Cursor;
android.database.sqlite.SQLiteDatabase;
android.graphics.Color;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.view.ViewGroup;
android.view.ViewGroup.LayoutParams;
android.widget.Button;
android.widget.ScrollView;
android.widget.TableLayout;
android.widget.TableRow;
android.widget.TextView;
android.widget.Toast;

public class ViewRecords extends ActionBarActivity {


Button b1;
TextView t1;
TableLayout tl1;
ScrollView sv;
SQLiteDatabase mydb=null;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_records);
//
b1=(Button)findViewById(R.id.btnBack);
//t1=(TextView)findViewById(R.id.txtResult);
myListener2 m=new myListener2();

//

b1.setOnClickListener((OnClickListener) m);
tl1 = (TableLayout)findViewById(R.id.myTableLayout);
//t1=(TextView)findViewById(R.id.textView1);
sv = (ScrollView)findViewById(R.id.scrollView901);
mydb=openOrCreateDatabase(cls.dbname,MODE_PRIVATE ,null)

;
Cursor c=null;
if(cls.viewtype==1)
{
c=mydb.rawQuery("Select * From Booking",null);
//Toast.makeText(ViewRecords.this, "Blood", Toas
t.LENGTH_LONG).show();
}
else if(cls.viewtype==2)
c=mydb.rawQuery("Select * From Booking",null);
else if(cls.viewtype==3)
c=mydb.rawQuery("Select * From Booking",null);
else if(cls.viewtype==4)
c=mydb.rawQuery("Select * From Booking",null);
c.moveToFirst();
StringBuilder sb1=new StringBuilder();
String Sc;
// TableRow tr1 = new TableRow(this);
// TextView b11 = new TextView(this);
//if(cls.viewtype==1)
//b11.setText("Booking");
//else if(cls.viewtype==2)
// b11.setText("Sand Details");
//else if(cls.viewtype==3)
// b11.setText("Brick Details");
// else if(cls.viewtype==4)
// b11.setText("Steel Rod Details");
//tr1.addView(b11);
// tl1.addView(tr1,new TableLayout.LayoutParams(LayoutParams.FI
LL_PARENT,LayoutParams.FILL_PARENT));
// tr1.setBackgroundColor(Color.BLUE);
//
TableRow tr11 = new TableRow(this);
// TextView b12 = new TextView(this);
// b12.setText("Records List");
// tr11.addView(b12);
// tl1.addView(tr11,new TableLayout.LayoutParams(LayoutParams.F
ILL_PARENT,LayoutParams.FILL_PARENT));
// tr11.setBackgroundColor(Color.GREEN);
// TableRow trheader = new TableRow(this);
//
TextView bheader = new TextView(this);
//
tl1.addView(trheader,new TableLayout.LayoutParams(LayoutPara
ms.FILL_PARENT,LayoutParams.FILL_PARENT));
// trheader.setBackgroundColor(Color.WHITE);
//
//
//
//
//

if(cls.viewtype==1)
bheader.setText("Booking");
else if(cls.viewtype==2)
bheader.setText("Sand");
else if(cls.viewtype==3)
// {
// bheader.setText("Brick");

//}
//else if(cls.viewtype==6)
//{
//bheader.setText("Steel Rod");
//}
int rowcount=0;

c.close();
//t1.setText(sb1.toString());
//
//

c=mydb.rawQuery("Select * From Booking",null);


c.moveToFirst();
//while (c.isAfterLast()==false)
{
//
//

Sc=c.getString(0);
Toast.makeText(ViewRecords.this, Sc, Toast.LENGT

H_LONG).show();
//
sb1.append(Sc+"\r\n");// + "\t" + c.getSt
ring(1) + "\t" + c.getString(2);
//
//
TableRow tr = new TableRow(this);
//
tr.setLayoutParams(new ViewGroup.LayoutParams(Vie
wGroup.LayoutParams.FILL_PARENT,
//
ViewGroup.LayoutParams.FILL_PARENT));
//
TextView b1 = new TextView(this);
// b1.setText("Booking");
// b1.setLayoutParams(new ViewGroup.LayoutParam
s(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
// tr.addView(b1);
//

TableRow tr2 = new TableRow(this);


// TextView b121 = new TextView(this);
// b121.setText(Sc);
// tr2.addView(b121);

//
tl1.addView(tr,new TableLayout.LayoutParams
(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//
tl1.addView(tr2,new TableLayout.LayoutParam
s(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//
if(rowcount%2==0)
//
{
// tr.setBackgroundColor(Color.BLUE);
// b1.setTextColor(Color.WHITE);
//
//
//
//
//
//
//

}
c.close();

}
else
{
//

tr.setBackgroundColor(Color.GREEN);

}
rowcount++;
c.moveToNext();

c=mydb.rawQuery("Select * From Booking",null);


c.moveToFirst();
while (c.isAfterLast()==false)
{
Sc=c.getString(0);
//Toast.makeText(ViewRecords.this, Sc, Toast.LEN
GTH_LONG).show();
sb1.append("Brick:" + Sc+"\r\n");// + "\t"
+ c.getString(1) + "\t" + c.getString(2);
//
TableRow tr = new TableRow(this);
TextView b1 = new TextView(this);
b1.setText("Booking");
tr.addView(b1);
TableRow tr2 = new TableRow(this);
TextView b121 = new TextView(this);
b121.setText("Route:"+Sc +",Mobile:" + c.getSt
ring(1) + ",Date:"+c.getString(2)+ ",Seat:"+c.getString(3));
tr2.addView(b121);
tl1.addView(tr,new TableLayout.LayoutParams(L
ayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
tl1.addView(tr2,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
if(rowcount%2==0)
{
tr.setBackgroundColor(Color.BLUE);
b1.setTextColor(Color.WHITE);
}
else
{
tr.setBackgroundColor(Color.GREEN);
}
rowcount++;
c.moveToNext();
}
c.close();
c=mydb.rawQuery("Select * From Booking",null);
c.moveToFirst();
//while (c.isAfterLast()==false)
// {
//
//

Sc=c.getString(0);
Toast.makeText(ViewRecords.this, Sc, Toast.LENGT

H_LONG).show();
//
sb1.append("SteelRod:" + Sc+"\r\n");// +
"\t" + c.getString(1) + "\t" + c.getString(2);
//
// TableRow tr = new TableRow(this);

//

// TextView b1 = new TextView(this);


// b1.setText("SteelRod");
//
tr.addView(b1);
TableRow tr2 = new TableRow(this);

//
//

TextView b121 = new TextView(this);


b121.setText(Sc);
//

tr2.addView(b121);

// tl1.addView(tr,new TableLayout.LayoutParams
(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//
tl1.addView(tr2,new TableLayout.LayoutParam
s(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//
if(rowcount%2==0)
//
{
//
//
tr.setBackgroundColor(Color.BLUE);
//
b1.setTextColor(Color.WHITE);
//
//
//

}
else
{
//

//
//
//

tr.setBackgroundColor(Color.GREEN);
}
rowcount++;
c.moveToNext();

// }
c.close();

mydb.close();
}
/*Cursor cr=
mydb.rawQuery("Select * From Subjects",null);
cr.moveToFirst();
StringBuilder sb=new StringBuilder();
while( cr.isAfterLast()==false)
{
sb.append(cr.getString(0) +"\t" + cr.getString(1) +"\t" + cr.get
String(2) +"\r\n");
cr.moveToNext();
}
cr.close();*/
//t1.setText(sb.toString());
//mydb.close();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar i
f it is present.
getMenuInflater().inflate(R.menu.view_records, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar wi
ll
// automatically handle clicks on the Home/Up button, so
long
// as you specify a parent activity in AndroidManifest.x
ml.

int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
class myListener2 implements View.OnClickListener
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
//case R.id.btnSave:
//String s1=t1.getText().toString();
//

mydb.execSQL("Delete From Subjects Where Subject

Code='" + s1 + "'");
//
mydb.execSQL("Insert into Subjects Values('" + s
1 + "','" + s2 + "','" + s3 + "')");
//Toast.makeText(AddSubject.this, "Subject Details Saved", Toast
.LENGTH_LONG).show();
//break;
//case R.id.btnBack:
//
finish();
//
break;
}
}
}
}
********************************************************************************
***************************
package com.example.gpsbustracker;
import android.support.v7.app.ActionBarActivity;

import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

android.app.Activity;
android.database.Cursor;
android.database.sqlite.SQLiteDatabase;
android.graphics.Color;
android.os.Bundle;
android.view.Menu;
android.view.MenuItem;
android.view.View;
android.view.ViewGroup;
android.view.ViewGroup.LayoutParams;
android.widget.Button;
android.widget.ScrollView;
android.widget.TableLayout;
android.widget.TableRow;
android.widget.TextView;
android.widget.Toast;

public class ViewRecords extends ActionBarActivity {

//

Button b1;
TextView t1;
TableLayout tl1;
ScrollView sv;
SQLiteDatabase mydb=null;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_records);
//
b1=(Button)findViewById(R.id.btnBack);
//t1=(TextView)findViewById(R.id.txtResult);
myListener2 m=new myListener2();
b1.setOnClickListener((OnClickListener) m);
tl1 = (TableLayout)findViewById(R.id.myTableLayout);
//t1=(TextView)findViewById(R.id.textView1);
sv = (ScrollView)findViewById(R.id.scrollView901);
mydb=openOrCreateDatabase(cls.dbname,MODE_PRIVATE ,null)

;
Cursor c=null;
if(cls.viewtype==1)
{
c=mydb.rawQuery("Select * From Booking",null);
//Toast.makeText(ViewRecords.this, "Blood", Toas
t.LENGTH_LONG).show();
}
else if(cls.viewtype==2)
c=mydb.rawQuery("Select * From Booking",null);
else if(cls.viewtype==3)
c=mydb.rawQuery("Select * From Booking",null);
else if(cls.viewtype==4)
c=mydb.rawQuery("Select * From Booking",null);
c.moveToFirst();
StringBuilder sb1=new StringBuilder();
String Sc;
// TableRow tr1 = new TableRow(this);
// TextView b11 = new TextView(this);
//if(cls.viewtype==1)
//b11.setText("Booking");
//else if(cls.viewtype==2)
// b11.setText("Sand Details");
//else if(cls.viewtype==3)
// b11.setText("Brick Details");
// else if(cls.viewtype==4)
// b11.setText("Steel Rod Details");
//tr1.addView(b11);
// tl1.addView(tr1,new TableLayout.LayoutParams(LayoutParams.FI
LL_PARENT,LayoutParams.FILL_PARENT));
// tr1.setBackgroundColor(Color.BLUE);
//
TableRow tr11 = new TableRow(this);
// TextView b12 = new TextView(this);
// b12.setText("Records List");
// tr11.addView(b12);
// tl1.addView(tr11,new TableLayout.LayoutParams(LayoutParams.F
ILL_PARENT,LayoutParams.FILL_PARENT));
// tr11.setBackgroundColor(Color.GREEN);

// TableRow trheader = new TableRow(this);


//
TextView bheader = new TextView(this);
//
tl1.addView(trheader,new TableLayout.LayoutParams(LayoutPara
ms.FILL_PARENT,LayoutParams.FILL_PARENT));
// trheader.setBackgroundColor(Color.WHITE);
//
//
//
//
//

if(cls.viewtype==1)
bheader.setText("Booking");
else if(cls.viewtype==2)
bheader.setText("Sand");
else if(cls.viewtype==3)
// {
// bheader.setText("Brick");
//}
//else if(cls.viewtype==6)
//{
//bheader.setText("Steel Rod");
//}
int rowcount=0;

c.close();
//t1.setText(sb1.toString());
//
//

c=mydb.rawQuery("Select * From Booking",null);


c.moveToFirst();
//while (c.isAfterLast()==false)
{
//
//

Sc=c.getString(0);
Toast.makeText(ViewRecords.this, Sc, Toast.LENGT

H_LONG).show();
//
sb1.append(Sc+"\r\n");// + "\t" + c.getSt
ring(1) + "\t" + c.getString(2);
//
//
TableRow tr = new TableRow(this);
//
tr.setLayoutParams(new ViewGroup.LayoutParams(Vie
wGroup.LayoutParams.FILL_PARENT,
//
ViewGroup.LayoutParams.FILL_PARENT));
//
TextView b1 = new TextView(this);
// b1.setText("Booking");
// b1.setLayoutParams(new ViewGroup.LayoutParam
s(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
// tr.addView(b1);
//

TableRow tr2 = new TableRow(this);


// TextView b121 = new TextView(this);
// b121.setText(Sc);
// tr2.addView(b121);

//
tl1.addView(tr,new TableLayout.LayoutParams
(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//
tl1.addView(tr2,new TableLayout.LayoutParam
s(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//
if(rowcount%2==0)
//
{

//
//
//
//
//

}
else
{
//

//
//
//
//

tr.setBackgroundColor(Color.BLUE);
b1.setTextColor(Color.WHITE);

tr.setBackgroundColor(Color.GREEN);

}
rowcount++;
c.moveToNext();

}
c.close();
c=mydb.rawQuery("Select * From Booking",null);
c.moveToFirst();
while (c.isAfterLast()==false)

{
Sc=c.getString(0);
//Toast.makeText(ViewRecords.this, Sc, Toast.LEN
GTH_LONG).show();
// sb1.append("Brick:" + Sc+"\r\n");// + "\t
" + c.getString(1) + "\t" + c.getString(2);
//
// TableRow tr = new TableRow(this);
// TextView b1 = new TextView(this);
// b1.setText("Booking");
// tr.addView(b1);
TableRow tr2 = new TableRow(this);
TextView b121 = new TextView(this);
b121.setText("Route:"+Sc +",Mobile:" + c.getSt
ring(1) + ",Date:"+c.getString(2)+ ",Seat:"+c.getString(3));
tr2.addView(b121);
// tl1.addView(tr,new TableLayout.LayoutParams
(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
tl1.addView(tr2,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
// if(rowcount%2==0)
// {
//
tr.setBackgroundColor(Color.BLUE);
//
b1.setTextColor(Color.WHITE);
//
//
//
//
//

}
else
{
tr.setBackgroundColor(Color.GREEN);
}
rowcount++;
c.moveToNext();

}
c.close();
//
//

c=mydb.rawQuery("Select * From Booking",null);


c.moveToFirst();
//while (c.isAfterLast()==false)
// {

//
//

Sc=c.getString(0);
Toast.makeText(ViewRecords.this, Sc, Toast.LENGT

H_LONG).show();
//
sb1.append("SteelRod:" + Sc+"\r\n");// +
"\t" + c.getString(1) + "\t" + c.getString(2);
//
// TableRow tr = new TableRow(this);
// TextView b1 = new TextView(this);
// b1.setText("SteelRod");
//
tr.addView(b1);
TableRow tr2 = new TableRow(this);
TextView b121 = new TextView(this);
b121.setText(Sc);

//
//
//
//

tr2.addView(b121);

// tl1.addView(tr,new TableLayout.LayoutParams
(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//
tl1.addView(tr2,new TableLayout.LayoutParam
s(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//
if(rowcount%2==0)
//
{
//
//
tr.setBackgroundColor(Color.BLUE);
//
b1.setTextColor(Color.WHITE);
//
//
//

}
else
{
//

//
//
//
//

tr.setBackgroundColor(Color.GREEN);
}
rowcount++;
c.moveToNext();

// }
c.close();

//mydb.close();
}
/*Cursor cr=
mydb.rawQuery("Select * From Subjects",null);
cr.moveToFirst();
StringBuilder sb=new StringBuilder();
while( cr.isAfterLast()==false)
{
sb.append(cr.getString(0) +"\t" + cr.getString(1) +"\t" + cr.get
String(2) +"\r\n");
cr.moveToNext();
}
cr.close();*/
//t1.setText(sb.toString());
//mydb.close();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar i

f it is present.
getMenuInflater().inflate(R.menu.view_records, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar wi
ll
// automatically handle clicks on the Home/Up button, so
long
// as you specify a parent activity in AndroidManifest.x
ml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
class myListener2 implements View.OnClickListener
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
//case R.id.btnSave:
//String s1=t1.getText().toString();
//

mydb.execSQL("Delete From Subjects Where Subject

Code='" + s1 + "'");
//
mydb.execSQL("Insert into Subjects Values('" + s
1 + "','" + s2 + "','" + s3 + "')");
//Toast.makeText(AddSubject.this, "Subject Details Saved", Toast
.LENGTH_LONG).show();
//break;
//case R.id.btnBack:
//
finish();
//
break;
}
}
}
}
*****************************************************************************
<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="com.example.building.ViewRecords" >
<ScrollView
android:id="@+id/scrollView901"
android:layout_width="fill_parent"

android:layout_height="fill_parent"
android:background="#FF0000"
android:fillViewport="true"
android:scrollbars="horizontal|vertical" >
<TableLayout
android:id="@+id/myTableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="left|top"
>

</TableLayout>
</ScrollView>
</RelativeLayout>

You might also like