Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 KB | None | 0 0
  1. import android.app.Activity;
  2. import android.content.Intent;
  3. import android.database.Cursor;
  4. import android.database.sqlite.SQLiteDatabase;
  5. import android.os.Bundle;
  6. import android.support.v4.widget.SimpleCursorAdapter;
  7. import android.text.Editable;
  8. import android.text.TextWatcher;
  9.  
  10. import android.view.Menu;
  11. import android.view.MenuItem;
  12. import android.view.View;
  13. import android.widget.AdapterView;
  14. import android.widget.EditText;
  15. import android.widget.ListView;
  16.  
  17. public class MainActivity extends Activity {
  18.  
  19. private MyDBHelper mydb;
  20. private SimpleCursorAdapter adapter;
  21. public static final String Row_ID = "row_id";
  22. EditText inputSearch;
  23. ListView dplist;
  24. @Override
  25. protected void onCreate(Bundle savedInstanceState) {
  26. super.onCreate(savedInstanceState);
  27. setContentView(R.layout.activity_main);
  28.  
  29. //********************************//
  30. //Begin of Database-Table1_Dept_List
  31. //********************************//
  32. dplist= (ListView) findViewById(R.id.list_view);
  33. //Instantiate database
  34. mydb =new MyDBHelper(this, null, null,4);
  35. SQLiteDatabase db =mydb.getReadableDatabase();
  36. //Removing duplicate values from table1_dept_list
  37. mydb.delete_dep_list();
  38. //Inserting into table1_dept_list
  39. mydb.add_dept_list("DLBIOCHEM","BioChemistry");
  40. mydb.add_dept_list("DLBIOTECH","BioTechnology");
  41. mydb.add_dept_list("DLBOT", "Botany");
  42. mydb.add_dept_list("DLCHEM","Chemistry");
  43. mydb.add_dept_list("DLCOM","Commerce");
  44. mydb.add_dept_list("DLCS","Computer Science");
  45. mydb.add_dept_list("DLECO","Economics");
  46. mydb.add_dept_list("DLEDU","Education");
  47. mydb.add_dept_list("DLENG","English");
  48. mydb.add_dept_list("DLEVS","Environmental Science");
  49. mydb.add_dept_list("DLFSN","Food Science and Nutrition");
  50. mydb.add_dept_list("DLGEO","Geology");
  51. mydb.add_dept_list("DLJMC", "Journalism and Massmedia Communication");
  52. mydb.add_dept_list("DLLIS","Library and Information Science");
  53. mydb.add_dept_list("DLMATH","Mathematics");
  54. mydb.add_dept_list("DLMICRO","Microbiology");
  55. mydb.add_dept_list("DLPE","Physical Education");
  56. mydb.add_dept_list("DLPHY","Physics");
  57. mydb.add_dept_list("DLPRIMS","Periyar Institute of Management Studies");
  58. mydb.add_dept_list("DLPSY","Psychology");
  59. mydb.add_dept_list("DLSOC","Sociology");
  60. mydb.add_dept_list("DLTAM", "Tamil");
  61. mydb.add_dept_list("DLTAD","Textile and Apparel Design");
  62. mydb.add_dept_list("DLZOO","Zoology");
  63.  
  64. //list view
  65. Cursor AllDeptList = mydb.get_dept_list();
  66. String[] from=new String[] {
  67. MyDBHelper.DEPT_LIST_COLUMN_NAME
  68. };
  69. int[] to=new int[] {R.id.dis_text};
  70. adapter = new SimpleCursorAdapter(this,R.layout.disp_text,AllDeptList,from,to,0 );
  71.  
  72. dplist.setAdapter(adapter);
  73. //********************************//
  74. //end of Database-Table1_Dept_List//
  75. //********************************//
  76.  
  77. //******************************//
  78. //Passing values to new activity//
  79. //******************************//
  80.  
  81. dplist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  82.  
  83. @Override
  84. public void onItemClick(AdapterView<?> arg0, View arg1, int position,
  85. long arg3) {
  86. // TODO Auto-generated method stub
  87.  
  88. Cursor cursor = (Cursor) dplist.getItemAtPosition(position);
  89. String dep_name = cursor.getString(cursor.getColumnIndex(MyDBHelper.DEPT_LIST_COLUMN_NAME));
  90. String dep_id = cursor.getString(cursor.getColumnIndex(MyDBHelper.DEPT_LIST_COLUMN_ID));
  91.  
  92. Intent intent_dp_list = new Intent(MainActivity.this,DepartmentDesignation.class);
  93. intent_dp_list.putExtra("dep_name",dep_name);
  94. intent_dp_list.putExtra("dep_id",dep_id);
  95. startActivity(intent_dp_list);
  96.  
  97. }
  98.  
  99. });
  100. //*********************************//
  101. //end of passing values to activity//
  102. //*********************************//
  103.  
  104. inputSearch = (EditText)findViewById(R.id.search_box);
  105. inputSearch.addTextChangedListener(new TextWatcher(){
  106.  
  107. @Override
  108. public void afterTextChanged(Editable arg0) {
  109. // TODO Auto-generated method stub
  110.  
  111.  
  112. }
  113.  
  114. @Override
  115. public void beforeTextChanged(CharSequence arg0, int arg1,
  116. int arg2, int arg3) {
  117. // TODO Auto-generated method stub
  118.  
  119. }
  120.  
  121. @Override
  122. public void onTextChanged(CharSequence cs, int arg1, int arg2,
  123. int arg3) {
  124. // TODO Auto-generated method stub
  125. MainActivity.this.adapter.getFilter().filter(cs);
  126.  
  127. }
  128.  
  129. });
  130.  
  131. }
  132.  
  133. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  134. xmlns:tools="http://schemas.android.com/tools"
  135. android:layout_width="match_parent"
  136. android:layout_height="match_parent"
  137. android:paddingBottom="@dimen/activity_vertical_margin"
  138. android:paddingLeft="@dimen/activity_horizontal_margin"
  139. android:paddingRight="@dimen/activity_horizontal_margin"
  140. android:paddingTop="@dimen/activity_vertical_margin"
  141. tools:context=".MainActivity"
  142. android:orientation="horizontal" >
  143.  
  144.  
  145.  
  146. <EditText android:id="@+id/search_box"
  147. android:layout_width="fill_parent"
  148. android:layout_height="wrap_content"
  149. android:hint="@string/searchhint" />
  150. <ListView android:id ="@+id/list_view"
  151. android:layout_width="match_parent"
  152. android:layout_height="wrap_content" />
  153.  
  154.  
  155.  
  156. </LinearLayout>
  157.  
  158. <?xml version="1.0" encoding="utf-8"?>
  159. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  160. package="com.example.contact"
  161. android:versionCode="1"
  162. android:versionName="1.0" >
  163.  
  164. <uses-sdk
  165. android:minSdkVersion="8"
  166. android:targetSdkVersion="18" />
  167. <uses-permission android:name="android.permission.CALL_PHONE" />
  168. <application
  169. android:allowBackup="true"
  170. android:icon="@drawable/ic_launcher"
  171. android:label="@string/app_name"
  172. android:theme="@style/AppTheme" >
  173. <activity
  174. android:name="com.example.contact.MainActivity"
  175. android:label="@string/app_name"
  176. android:windowSoftInputMode="stateHidden" >
  177.  
  178. <intent-filter>
  179. <action android:name="android.intent.action.MAIN" />
  180. <action android:name="android.intent.action.SEARCH" />
  181. <category android:name="android.intent.category.LAUNCHER" />
  182. </intent-filter>
  183.  
  184.  
  185. </activity>
  186. <activity android:name="com.example.contact.DepartmentDesignation" />
  187. <activity android:name="com.example.contact.PersonsListActivity" />
  188. <activity android:name="com.example.contact.HodDetails" />
  189. </application>
  190.  
  191. </manifest>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement