0% found this document useful (0 votes)
85 views31 pages

App Manifest

This document contains code snippets from an Android application manifest file, color resources file, Gradle build file, menu layout, main activity layout, and main activity Java code. The manifest declares permissions, application components and their properties. The color resources set the primary and accent colors. The Gradle file configures the build. The menu layout defines a share menu item. The main activity layout contains UI elements like buttons and text. The main activity code handles button clicks, ads, and the share menu item.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views31 pages

App Manifest

This document contains code snippets from an Android application manifest file, color resources file, Gradle build file, menu layout, main activity layout, and main activity Java code. The manifest declares permissions, application components and their properties. The color resources set the primary and accent colors. The Gradle file configures the build. The menu layout defines a share menu item. The main activity layout contains UI elements like buttons and text. The main activity code handles button clicks, ads, and the share menu item.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

App-MANIFEST:

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bhavin.srcwcomputersciencequiz">

<uses-permission android:name="android.permission.INTERNET" />


<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".SRCWComputerScienceQuiz"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
<activity
android:name=".C"
android:label="@string/title_activity_c"
android:parentActivityName=".SRCWComputerScienceQuiz"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"

android:value="com.example.bhavin.srcwcomputersciencequiz.SRCWComputerScienceQui
z" />
</activity>
<activity
android:name=".CUnitOne"
android:label="@string/title_activity_cunit_one"
android:parentActivityName=".C"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.bhavin.srcwcomputersciencequiz.C" />
</activity>
</application>

</manifest>

App-COLOUR:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#d201fc</color>
<color name="colorPrimaryDark">#d201fc</color>
<color name="colorAccent">#d201fc</color>
</resources>
Gradle-BUILD GRADLE:
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "com.example.bhavin.srcwcomputersciencequiz"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//testCompile 'junit:junit:4.12' Commented [B1]: // will not be there

compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services-ads:7.8.0'
}
App-MENU:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"

tools:context="com.example.bhavin.srcwcomputersciencequiz.SRCWComputerScienceQuiz
">
<item
android:id="@+id/action_share"
android:orderInCategory="100"
android:title="Share"
app:showAsAction="always"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>
/>
</menu>
App- CONTENT :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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"
android:background="#fdfdfd"
app:layout_behavior="@string/appbar_scrolling_view_behavior"

tools:context="com.example.bhavin.srcwcomputersciencequiz.SRCWComputerScienceQuiz
"
tools:showIn="@layout/activity_srcwcomputer_science_quiz">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/banner"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#d201fc"
android:layout_marginTop="130dp"
android:textSize="20dp"
android:textAlignment="center"
android:text="Accredited by NAAC,An 9001:2008 Certified Institution Affiliated
to Bharathiar University \nCoimbatore-641 044"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="230dp"
android:text="Select the subject to start quiz"
android:textColor="#d201fc"
android:textSize="18dp"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="250dp"
android:layout_marginBottom="55dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="@+id/button16"
android:onClick="ad"
android:background="#d201fc"
android:text="ADIS"
android:textSize="25dp"
android:textColor="#fdfdfd"/>

</LinearLayout>
</ScrollView>
</RelativeLayout>

App-JAVA:
package com.example.bhavin.srcwcomputersciencequiz;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.ShareActionProvider;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

public class SRCWComputerScienceQuiz extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_srcwcomputer_science_quiz);
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_srcwcomputer_science_quiz, menu);
MenuItem item = (MenuItem) menu.findItem(R.id.action_share);
ShareActionProvider shareAction = (ShareActionProvider)
MenuItemCompat.getActionProvider(item);
Intent shareIntent = new Intent(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_TEXT, "Android Application for Quiz in Computer
Science " + "http://play.google.com/store/apps/details?id=" + getPackageName())
.putExtra(Intent.EXTRA_SUBJECT, "Quiz on Computer Science Subjects
exclusively build on the basis of Sri Ramakrishna College of ARts and Science For Wormen
Syllubus")
.setType("text/plain");
shareAction.setShareIntent(shareIntent);
return true;
}
public void ad(View view) {
String button_ad;
button_ad = ((Button) view).getText().toString();
if (button_ad.equals("ADIS")) {
Intent intent = new Intent(this, ADIS.class);
startActivity(intent);
}
}

}
C CONTENT:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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"
android:background="#fdfdfd"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.bhavin.srcwcomputersciencequiz.CUnitOne"
tools:showIn="@layout/activity_cunit_one">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="1. The term computer is derived from the word"
android:textColor="#d201fc"
android:textSize="20dp"
/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/radiogroup1"
android:layout_marginTop="10dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/r1"
android:textSize="18dp"
android:textColor="#d201fc"
android:text=" Compute"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/r2"
android:textSize="18dp"
android:textColor="#d201fc"
android:text=" Compete "
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/r3"
android:textSize="18dp"
android:textColor="#d201fc"
android:text=" Calculate "
/>
</RadioGroup>
</LinearLayout>
</ScrollView>
</RelativeLayout>

App- C JAVA:
package com.example.bhavin.srcwcomputersciencequiz;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.graphics.Color;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class CPlusPlusUnitOne extends AppCompatActivity {


TextView tv,tv1,tv6,tv3,tv4,tv5,tv7,tv8;
RadioGroup
rg1,rg2,rg3,rg4,rg5,rg6,rg7,rg8,rg9,rg10,rg11,rg12,rg13,rg14,rg15,rg16,rg17,rg18,rg19,
rg20,rg21,rg22,rg23,rg24,rg25,rg26,rg27,rg28,rg29,rg30,rg31,rg32,rg33,rg34,rg35,rg36,
rg37,rg38,rg39,rg40,rg41,rg42,rg43,rg44,rg45,rg46,rg47,rg48,rg49,rg50;
RadioButton
r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,r18,r19,r20,r21,r22,r23,r24,r2
5,r26,r27,r28,r29,r30,r31,r32,r33,r34,r35,r36,r37,r38,r39,r40,r41,r42,r43,r44,r45,r46,r4
7,r48,r49,r50,r51,r52,r53,r54,r55,r56,r57,r58,r59,r60,r61,r62,r63,r64,r65,r66,r67,r68,r6
9,r70,r71,r72,r73,r74,r75,r76,r77,r78,r79,r80,r81,r82,r83,r84,r85,r86,r87,r88,r89,r90,r9
1,r92,r93,r94,r95,r96,r97,r98,r99,r100,r101,r102,r103,r104,r105,r106,r107,r108,r109,r1
10,r111,r112,r113,r114,r115,r116,r117,r118,r119,r120,r121,r122,r123,r124,r125,r126,r1
27,r128,r129,r130,r131,r132,r133,r134,r135,r136,r137,r138,r139,r140,r141,r142,r143,r1
44,r145,r146,r147,r148,r149,r150;
Button btn;
double count=0,correct=0,wrong=0,question=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cplus_plus_unit_one);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
tv = (TextView) findViewById(R.id.textView);
tv1 = (TextView) findViewById(R.id.textView1);
tv3 = (TextView) findViewById(R.id.textView3);
tv4 = (TextView) findViewById(R.id.textView4);
tv5 = (TextView) findViewById(R.id.textView5);
tv6 = (TextView) findViewById(R.id.textView6);
tv7 = (TextView) findViewById(R.id.textView7);
tv8 = (TextView) findViewById(R.id.textView8);
rg1 = (RadioGroup) findViewById(R.id.radiogroup1);
r1 = (RadioButton) findViewById(R.id.r1);
r2 = (RadioButton) findViewById(R.id.r2);
r3 = (RadioButton) findViewById(R.id.r3);
tv.setVisibility(View.INVISIBLE);
tv1.setVisibility(View.INVISIBLE);
tv3.setVisibility(View.INVISIBLE);
tv4.setVisibility(View.INVISIBLE);
tv5.setVisibility(View.INVISIBLE);
tv6.setVisibility(View.INVISIBLE);
tv7.setVisibility(View.INVISIBLE);
tv8.setVisibility(View.INVISIBLE);
btn = (Button) findViewById(R.id.buttons);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(r1.isChecked()){
count++;
correct++;
question++;
r1.setTextColor(Color.GREEN);
r2.setTextColor(Color.parseColor("#d201fc"));
r3.setTextColor(Color.parseColor("#d201fc"));
}
else
{
if(r2.isChecked())
{
count=count-0.01;
wrong++;
question++;
r1.setTextColor(Color.GREEN);
r2.setTextColor(Color.RED);
r3.setTextColor(Color.parseColor("#d201fc"));
}
else
{
if(r3.isChecked())
{
count=count-0.01;
wrong++;
question++;
r1.setTextColor(Color.GREEN);
r3.setTextColor(Color.RED);
r2.setTextColor(Color.parseColor("#d201fc"));
}
else
{
r1.setTextColor(Color.GREEN);
}
}
}
tv.setVisibility(View.VISIBLE);
tv1.setVisibility(View.VISIBLE);
tv3.setVisibility(View.VISIBLE);
tv4.setVisibility(View.VISIBLE);
tv5.setVisibility(View.VISIBLE);
tv6.setVisibility(View.VISIBLE);
tv7.setVisibility(View.VISIBLE);
tv8.setVisibility(View.VISIBLE);
tv.setText(Double.toString(count));
tv4.setText(Double.toString(correct));
tv6.setText(Double.toString(wrong));
tv8.setText(Double.toString(question));
count=0;
correct=0;
wrong=0;
question=0;

}
});

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

}
Database

ADD TO CART
TOTAL AMOUNT
SEND THROUGH EMAIL

SEND THROUGH EMAIL WITH TOTAL AMOUNT OF MEDICINAL PLANT:


MESSAGE SENDED

View product list


NAME TYPE PRIMARY KEY
ID INTEGER YES
ITEM_NAME TEXT
PRICE INTEGER

Order Product List


NAME TYPE PRIMARY KEY
ID INTEGER YES
ITEM_NAME TEXT
PRICE INTEGER
QUANTITY TEXT
CONNECTIVITY CODING

package com.example.logeshwari.medicinalplantsanditsuses;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

public void Aloevera(View view)


{
String button1_Aloevera;
button1_Aloevera = ((Button) view).getText().toString();
if(button1_Aloevera.equals("Aloevera"))
{
Intent intent =new Intent(this, Aloevera.class );
startActivity(intent);
}
}

public void amaltas(View view)


{
String button2_amaltas;
button2_amaltas= ((Button) view).getText().toString();
if(button2_amaltas.equals("Amaltas"))
{
Intent intent =new Intent(this, amaltas.class);
startActivity(intent);
}

public void Amla(View view)


{
String button3_Amla;
button3_Amla = ((Button) view).getText().toString();
if(button3_Amla.equals("Amla"))
{
Intent intent =new Intent(this, Amla.class );
startActivity(intent);
}

public void ampalaya(View view)


{
String button4_ampalaya;
button4_ampalaya= ((Button) view).getText().toString();
if(button4_ampalaya.equals("Ampalaya"))
{
Intent intent =new Intent(this, ampalaya.class);
startActivity(intent);
}

public void arjuna(View view)


{
String button5_arjuna;
button5_arjuna= ((Button) view).getText().toString();
if(button5_arjuna.equals("Arjuna"))
{
Intent intent =new Intent(this, arjuna.class);
startActivity(intent);
}

public void Ashok(View view)


{
String button6_Ashok;
button6_Ashok = ((Button) view).getText().toString();
if(button6_Ashok.equals("Ashok"))
{
Intent intent =new Intent(this, Ashok.class );
startActivity(intent);
}

public void Aswagandha(View view)


{
String button7_Aswagandha;
button7_Aswagandha = ((Button) view).getText().toString();
if(button7_Aswagandha.equals("Aswagandha"))
{
Intent intent =new Intent(this, Aswagandha.class );
startActivity(intent);
}

public void Bael (View view)


{
String button8_Bael;
button8_Bael = ((Button) view).getText().toString();
if(button8_Bael.equals("Bael / Bilya"))
{
Intent intent =new Intent(this, Bael.class );
startActivity(intent);
}

public void Bahada(View view)


{
String button9_Bahada;
button9_Bahada = ((Button) view).getText().toString();
if(button9_Bahada.equals("Bahada"))
{
Intent intent =new Intent(this, Bahada.class);
startActivity(intent);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}
DATABASE CODING
package com.example.logeshwari.medicinalplantsanditsuses;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextWatcher;

public class DatabaseHelper extends SQLiteOpenHelper {


public static final String DATABASE_NAME = "Items.dp";
public static final String TABLE_NAME = "items_table";
public static final String COL_1 = "ID";
public static final String COL_2 = "ITEM_NAME";
public static final String COL_3 = "PRICE";
public static final String TABLE_NAME_2 = "cart_table";
public static final String COL_4 = "ID";
public static final String COL_5 = "ITEM_NAME";
public static final String COL_6 = "PRICE";
public static final String COL_7 = "QUANTITY";

public DatabaseHelper(Context context) {


super(context, DATABASE_NAME, null, 1); // pass the values for constructor

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("create table " + TABLE_NAME + "(ID INTEGER
PRIMARY KEY AUTOINCREMENT, ITEM_NAME TEXT, PRICE INTEGER)");
sqLiteDatabase.execSQL("create table " + TABLE_NAME_2 + "(ID INTEGER
PRIMARY KEY AUTOINCREMENT, ITEM_NAME TEXT, PRICE INTEGER,
QUANTITY TEXT)");
String[] items = {
"Aloevera ", "21",
"Amaltas", "24",
"Amla", "22",
"Ampalaya", "28",
"Vidarikanda", "25"

};

for(int i=0; i<items.length; i++) {


sqLiteDatabase.execSQL("INSERT INTO " + TABLE_NAME + "(" + COL_2 + ", "
+ COL_3 + ") VALUES ('" + items[i] + "', " + Integer.parseInt(items[i+1]) + ")");
i=i+1;
}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME_2);
onCreate(sqLiteDatabase);
}

public Cursor getAllProducts() {


String[] variable = {COL_1, COL_2, COL_3};
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
Cursor cursor = sqLiteDatabase.query(TABLE_NAME, variable,null,null,null,null,null);
return cursor;
}

public Cursor getAllCartItems() {


String[] variable = {COL_4, COL_5, COL_6, COL_7};
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
Cursor cursor = sqLiteDatabase.query(TABLE_NAME_2,
variable,null,null,null,null,null);
return cursor;
}

public Cursor getItemName(String id) {


String selectQuery = "SELECT "+ COL_2 +", "+COL_3+" FROM " + TABLE_NAME
+" WHERE " + COL_1 + " = '" + id + "'";
SQLiteDatabase rdatabase = this.getReadableDatabase();
Cursor cursor = rdatabase.rawQuery(selectQuery, null);
return cursor;
}

public String insertIntoCart(String item_name, int price, int quantity) {


Integer existing_quantity= 0, final_quantity = 0 ;
String error = "no_error";
String selectQuery = "SELECT "+COL_7+" FROM " + TABLE_NAME_2 +" WHERE
" + COL_5 + " = '" + item_name + "'";
SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
Cursor cursor = sqLiteDatabase.rawQuery(selectQuery, null);
if (cursor.getCount() == 0) {
ContentValues contentValues = new ContentValues();
contentValues.put(COL_5, item_name);
contentValues.put(COL_6, price);
contentValues.put(COL_7, quantity);
try {
sqLiteDatabase.insert(TABLE_NAME_2, null, contentValues);
}
catch (Exception e){
error = e.getMessage().toString();
}
}
else{
if (cursor.moveToFirst()) {
existing_quantity = Integer.parseInt(cursor.getString(0).toString());
}
final_quantity = existing_quantity + quantity;
String where = "ITEM_NAME=?";
String[] whereArgs = new String[] {String.valueOf(item_name)};
ContentValues dataToInsert = new ContentValues();
dataToInsert.put(COL_7, final_quantity);
try{
sqLiteDatabase.update(TABLE_NAME_2, dataToInsert, where, whereArgs);
}
catch (Exception e){
error = e.getMessage().toString();
}
}
return error;

public void DeleteItem(String item_id) {


SQLiteDatabase database = this.getWritableDatabase();
database.execSQL("DELETE FROM " + TABLE_NAME_2 + " WHERE " + COL_5 +
"= '" + item_id + "'");
database.close();
}
}

PRODUCT

public class ProductAdapter extends ArrayAdapter<Product> {


public ProductAdapter(Context context, ArrayList<Product> resource) {
super(context, 0, resource);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
Product product = getItem(position);

// Check if an existing view is being reused, otherwise inflate the view


if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.productrow,
parent, false);
}

// Lookup view for data population


TextView t_id = (TextView) convertView.findViewById(R.id.item_id);
TextView t_name = (TextView) convertView.findViewById(R.id.item_name);
TextView t_price = (TextView) convertView.findViewById(R.id.item_price);

// Populate the data into the template view using the data object
t_id.setText(product.id);
t_name.setText(product.name);
t_price.setText("Rs."+product.price);

// Return the completed view to render on screen


return convertView;
}

CART

package com.example.logeshwari.medicinalplantsanditsuses;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.InputMismatchException;

public class CartItemAdapter extends ArrayAdapter<CartItem> {


public CartItemAdapter(Context context, ArrayList<CartItem> resource) {
super(context, 0, resource);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
CartItem cartItem = getItem(position);

// Check if an existing view is being reused, otherwise inflate the view


if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.cart_row,
parent, false);
}

// Lookup view for data population


TextView t_id = (TextView) convertView.findViewById(R.id.cart_item_id);
TextView t_name = (TextView) convertView.findViewById(R.id.cart_item_name);
TextView t_price = (TextView) convertView.findViewById(R.id.cart_item_price);
TextView t_amount = (TextView) convertView.findViewById(R.id.total_amount);

// Populate the data into the template view using the data object
t_id.setText(cartItem.id);
t_name.setText(cartItem.name);
t_price.setText(cartItem.quantity+"/"+cartItem.price);
Integer amount = Integer.parseInt(cartItem.price.toString())*
Integer.parseInt(cartItem.quantity.toString());
t_amount.setText(amount.toString());

// Return the completed view to render on screen


return convertView;
}

DATABASE ROW CODING


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="55dp"
android:background="@color/common_action_bar_splitter">

<TextView
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:id="@+id/item_id"
android:text="1"
android:gravity="center"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>

<TextView
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_toRightOf="@id/item_id"
android:id="@+id/item_name"
android:text="Avacada"
android:gravity="center"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>
<TextView
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/item_name"
android:id="@+id/item_price"
android:text="Rs.15"
android:gravity="center"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>

</RelativeLayout>

CART ROW

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="40dp"
android:orientation="horizontal"
android:background="@color/common_action_bar_splitter">

<TextView
android:layout_width="60dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:id="@+id/cart_item_id"
android:text="S.no"
android:gravity="center"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>

<TextView
android:layout_width="120dp"
android:layout_height="50dp"
android:layout_toRightOf="@id/cart_item_id"
android:id="@+id/cart_item_name"
android:text="Name"
android:gravity="center"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>

<TextView
android:layout_width="90dp"
android:layout_height="50dp"
android:layout_toRightOf="@+id/cart_item_name"
android:id="@+id/cart_item_price"
android:text="Qty/Price"
android:gravity="center"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"/>

<TextView
android:layout_width="90dp"
android:layout_height="50dp"
android:layout_toRightOf="@+id/cart_item_price"
android:id="@+id/total_amount"
android:text="Amount"
android:gravity="center"
</RelativeLayout>

You might also like