Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.app.Activity;
- import android.content.Intent;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.os.Bundle;
- import android.support.v4.widget.SimpleCursorAdapter;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.EditText;
- import android.widget.ListView;
- public class MainActivity extends Activity {
- private MyDBHelper mydb;
- private SimpleCursorAdapter adapter;
- public static final String Row_ID = "row_id";
- EditText inputSearch;
- ListView dplist;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- //********************************//
- //Begin of Database-Table1_Dept_List
- //********************************//
- dplist= (ListView) findViewById(R.id.list_view);
- //Instantiate database
- mydb =new MyDBHelper(this, null, null,4);
- SQLiteDatabase db =mydb.getReadableDatabase();
- //Removing duplicate values from table1_dept_list
- mydb.delete_dep_list();
- //Inserting into table1_dept_list
- mydb.add_dept_list("DLBIOCHEM","BioChemistry");
- mydb.add_dept_list("DLBIOTECH","BioTechnology");
- mydb.add_dept_list("DLBOT", "Botany");
- mydb.add_dept_list("DLCHEM","Chemistry");
- mydb.add_dept_list("DLCOM","Commerce");
- mydb.add_dept_list("DLCS","Computer Science");
- mydb.add_dept_list("DLECO","Economics");
- mydb.add_dept_list("DLEDU","Education");
- mydb.add_dept_list("DLENG","English");
- mydb.add_dept_list("DLEVS","Environmental Science");
- mydb.add_dept_list("DLFSN","Food Science and Nutrition");
- mydb.add_dept_list("DLGEO","Geology");
- mydb.add_dept_list("DLJMC", "Journalism and Massmedia Communication");
- mydb.add_dept_list("DLLIS","Library and Information Science");
- mydb.add_dept_list("DLMATH","Mathematics");
- mydb.add_dept_list("DLMICRO","Microbiology");
- mydb.add_dept_list("DLPE","Physical Education");
- mydb.add_dept_list("DLPHY","Physics");
- mydb.add_dept_list("DLPRIMS","Periyar Institute of Management Studies");
- mydb.add_dept_list("DLPSY","Psychology");
- mydb.add_dept_list("DLSOC","Sociology");
- mydb.add_dept_list("DLTAM", "Tamil");
- mydb.add_dept_list("DLTAD","Textile and Apparel Design");
- mydb.add_dept_list("DLZOO","Zoology");
- //list view
- Cursor AllDeptList = mydb.get_dept_list();
- String[] from=new String[] {
- MyDBHelper.DEPT_LIST_COLUMN_NAME
- };
- int[] to=new int[] {R.id.dis_text};
- adapter = new SimpleCursorAdapter(this,R.layout.disp_text,AllDeptList,from,to,0 );
- dplist.setAdapter(adapter);
- //********************************//
- //end of Database-Table1_Dept_List//
- //********************************//
- //******************************//
- //Passing values to new activity//
- //******************************//
- dplist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1, int position,
- long arg3) {
- // TODO Auto-generated method stub
- Cursor cursor = (Cursor) dplist.getItemAtPosition(position);
- String dep_name = cursor.getString(cursor.getColumnIndex(MyDBHelper.DEPT_LIST_COLUMN_NAME));
- String dep_id = cursor.getString(cursor.getColumnIndex(MyDBHelper.DEPT_LIST_COLUMN_ID));
- Intent intent_dp_list = new Intent(MainActivity.this,DepartmentDesignation.class);
- intent_dp_list.putExtra("dep_name",dep_name);
- intent_dp_list.putExtra("dep_id",dep_id);
- startActivity(intent_dp_list);
- }
- });
- //*********************************//
- //end of passing values to activity//
- //*********************************//
- inputSearch = (EditText)findViewById(R.id.search_box);
- inputSearch.addTextChangedListener(new TextWatcher(){
- @Override
- public void afterTextChanged(Editable arg0) {
- // TODO Auto-generated method stub
- }
- @Override
- public void beforeTextChanged(CharSequence arg0, int arg1,
- int arg2, int arg3) {
- // TODO Auto-generated method stub
- }
- @Override
- public void onTextChanged(CharSequence cs, int arg1, int arg2,
- int arg3) {
- // TODO Auto-generated method stub
- MainActivity.this.adapter.getFilter().filter(cs);
- }
- });
- }
- <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: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"
- android:orientation="horizontal" >
- <EditText android:id="@+id/search_box"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:hint="@string/searchhint" />
- <ListView android:id ="@+id/list_view"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.contact"
- android:versionCode="1"
- android:versionName="1.0" >
- <uses-sdk
- android:minSdkVersion="8"
- android:targetSdkVersion="18" />
- <uses-permission android:name="android.permission.CALL_PHONE" />
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name="com.example.contact.MainActivity"
- android:label="@string/app_name"
- android:windowSoftInputMode="stateHidden" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <action android:name="android.intent.action.SEARCH" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity android:name="com.example.contact.DepartmentDesignation" />
- <activity android:name="com.example.contact.PersonsListActivity" />
- <activity android:name="com.example.contact.HodDetails" />
- </application>
- </manifest>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement