0% found this document useful (0 votes)
6 views4 pages

Linearlayout: @override

The document outlines an Android application that allows users to add notes with a date and content. It includes XML layout for the user interface, Java code for the main activity that handles user input and note insertion, a content provider for managing note data, and a database helper class for SQLite database operations. The manifest file specifies application metadata and permissions for the content provider.

Uploaded by

jocox65721
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)
6 views4 pages

Linearlayout: @override

The document outlines an Android application that allows users to add notes with a date and content. It includes XML layout for the user interface, Java code for the main activity that handles user input and note insertion, a content provider for managing note data, and a database helper class for SQLite database operations. The manifest file specifies application metadata and permissions for the content provider.

Uploaded by

jocox65721
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/ 4

Xml

<?xml version="1.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"
tools:context=".MainActivity"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"

android:layout_height="wrap_content"
android:text="Enter Date:" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txt_date" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter Note Content:" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txt_Content"
android:height="200dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Note"
android:id="@+id/btn_add_note" />
</LinearLayout>

MainActivity
package com.example.notesprovider;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
EditText txtDate,txtContent;
Button btnAddNote;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtDate=(EditText)findViewById(R.id.txt_date);
txtContent=(EditText)findViewById(R.id.txt_Content);
btnAddNote=(Button)findViewById(R.id.btn_add_note);
btnAddNote.setOnClickListener(this);
}

// @Override
// public boolean onCreateOptionsMenu(Menu menu) {
//// Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.main, menu);
// return true;
// }
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.equals(btnAddNote))
{
String sdate=txtDate.getText().toString();
String scontent=txtContent.getText().toString();
ContentValues values = new ContentValues();
values.put("note_date",sdate);
values.put("content",scontent);

getContentResolver().insert(Uri.parse("content://com.example.notesprovider/
notes"),
values);

Toast.makeText(getBaseContext(),"Data Inserted Successfully",

Toast.LENGTH_LONG).show();

}
}
}

NotesProvider
package com.example.notesprovider;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
public class NotesProvider extends ContentProvider
{

static final String URL = "content://com.example.notesprovider/notes";


SQLiteDatabase db;
ProviderDatabase dbHelper;
static final UriMatcher uriMatcher;
static{
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI("com.example.notesprovider", "notes",1);
}
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getType(Uri arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public Uri insert(Uri arg0, ContentValues cv) {
// TODO Auto-generated method stub
db = dbHelper.getWritableDatabase();
db.insert(ProviderDatabase.TABLE_NAME,null,cv);
db.close();
return null;
}
@Override
public boolean onCreate() {
// TODO Auto-generated method stub
dbHelper=new

ProviderDatabase(getContext(),ProviderDatabase.DATABASE_NAME+".db",null,1);
return (db == null)? false:true;
}
@Override
public Cursor query(Uri uri, String[] arg1, String arg2, String[] arg3,

String arg4) {
// TODO Auto-generated method stub
Cursor cursor=null;

db = dbHelper.getReadableDatabase();
cursor=

db.query(ProviderDatabase.TABLE_NAME,arg1,arg2,arg3,arg4,null,null);
return cursor;
}
@Override
public int update(Uri arg0, ContentValues arg1, String arg2, String[]
arg3) {
// TODO Auto-generated method stub
return 0;
}
}

ProviderDatabase
package com.example.notesprovider;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class ProviderDatabase extends SQLiteOpenHelper
{
public static String DATABASE_NAME="noteprovider";
public static String TABLE_NAME="notes";
public static String COLUMN_DATE="note_date";
public static String COLUMN_NOTE="content";
public ProviderDatabase(Context context, String name,
CursorFactory factory, int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("create table notes (note_date TEXT,content TEXT)");

}
@Override
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {

// TODO Auto-generated method stub


}
}

Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NotesProvider"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<provider android:name="NotesProvider"
android:authorities="com.example.notesprovider"
android:exported="true"/>
</application>

</manifest>

You might also like