Guest User

EmployeeList.java

a guest
May 9th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.21 KB | None | 0 0
  1. package com.example.mydbtest;
  2.  
  3. import android.app.Activity;
  4. import android.app.Dialog;
  5. import android.content.Intent;
  6. import android.database.Cursor;
  7. import android.database.sqlite.SQLiteDatabase;
  8. import android.net.Uri;
  9. import android.os.Bundle;
  10. import android.util.Log;
  11. import android.view.View;
  12. import android.widget.AdapterView;
  13. import android.widget.AutoCompleteTextView;
  14. import android.widget.Button;
  15. import android.widget.ImageView;
  16. import android.widget.ListAdapter;
  17. import android.widget.ListView;
  18. import android.widget.SimpleCursorAdapter;
  19. import android.widget.TextView;
  20. import android.widget.Toast;
  21.  
  22. public class EmployeeList extends Activity {
  23.  
  24.     protected SQLiteDatabase db;
  25.     Cursor cursor, autocursor;
  26.     protected ListAdapter adapter;
  27.     protected ListView employeeList;
  28.     AutoCompleteTextView searchText;
  29.     /** Called when the activity is first created. */
  30.     @Override
  31.     public void onCreate(Bundle savedInstanceState) {
  32.         super.onCreate(savedInstanceState);
  33.         setContentView(R.layout.main);
  34.         db = (new DatabaseHelper(this)).getWritableDatabase();
  35.         //searchText = (EditText) findViewById (R.id.searchText);
  36.         employeeList = (ListView) findViewById (R.id.list);
  37.  
  38.         cursor = db.rawQuery("SELECT _id, member_name, title FROM employee", null);
  39.         adapter = new SimpleCursorAdapter(
  40.                 this,
  41.                 R.layout.employee_list_item,
  42.                 cursor,
  43.                 new String[] {"member_name","title"},
  44.                 new int[] {R.id.member_name, R.id.title});
  45.         employeeList.setAdapter(adapter);
  46.  
  47.         employeeList.setOnItemClickListener(listContentOnItemClickListener);
  48.  
  49.  
  50.  
  51.     }
  52.  
  53.     private ListView.OnItemClickListener listContentOnItemClickListener = new ListView.OnItemClickListener(){
  54.         public void onItemClick(AdapterView<?> parent, View view, int position, long id)
  55.         {
  56.  
  57.             autocursor = (Cursor) parent.getItemAtPosition(position);
  58.            
  59.             Log.i("cursor", autocursor.toString());
  60.  
  61.             String item_content1 = autocursor.getString(autocursor.getColumnIndexOrThrow(DatabaseHelper.MEMBER_NAME));
  62.             String item_content2 = autocursor.getString(autocursor.getColumnIndex(DatabaseHelper.TITLE));
  63.             String item_content3 = autocursor.getString(autocursor.getColumnIndex(DatabaseHelper.OFFICEPHONE));
  64.             final String item_content4 = autocursor.getString(autocursor.getColumnIndex(DatabaseHelper.CELLPHONE));
  65.             final String item_content5 = autocursor.getString(autocursor.getColumnIndex(DatabaseHelper.EMAIL));
  66.  
  67.             Dialog dialog = new Dialog(EmployeeList.this);
  68.             dialog.setContentView(R.layout.dialog);
  69.             dialog.setTitle(item_content1);
  70.             dialog.setCancelable(true);
  71.  
  72.             //set up text
  73.             TextView text = (TextView) dialog.findViewById(R.id.TextView01);
  74.             text.setText(item_content2 + item_content3 + item_content4 + item_content5);
  75.  
  76.             //set up image view
  77.             ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
  78.             img.setImageResource(R.drawable.ic_launcher);
  79.  
  80.  
  81.             Toast.makeText(getBaseContext(), "Click", Toast.LENGTH_LONG).show();
  82.  
  83.             Button call = (Button) dialog.findViewById(R.id.Call);
  84.             Button sms = (Button) dialog.findViewById(R.id.SMS);
  85.             Button email = (Button) dialog.findViewById(R.id.Email);
  86.  
  87.  
  88.  
  89.             call.setOnClickListener(new View.OnClickListener() {
  90.                 @Override
  91.                 public void onClick(View v) {
  92.                     Intent callIntent = new Intent(Intent.ACTION_CALL);
  93.                     callIntent.setData(Uri.parse("tel:"+item_content4));
  94.                     startActivity(callIntent);
  95.                 }
  96.             });
  97.  
  98.             sms.setOnClickListener(new View.OnClickListener() {
  99.  
  100.                 @Override
  101.                 public void onClick(View arg0) {
  102.                     // TODO Auto-generated method stub
  103.                     Intent smsIntent = new Intent(Intent.ACTION_VIEW);
  104.                     smsIntent.setData(Uri.parse("sms:"+item_content4));
  105.                     startActivity(smsIntent);
  106.  
  107.                 }
  108.             });
  109.  
  110.             email.setOnClickListener(new View.OnClickListener() {
  111.  
  112.                 @Override
  113.                 public void onClick(View arg0) {
  114.                     // TODO Auto-generated method stub
  115.  
  116.                     Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
  117.                     String aEmailList[] = { item_content5 };
  118.                     emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
  119.                     emailIntent.setType("plain/text");
  120.                     startActivity(emailIntent);
  121.                 }
  122.             });
  123.             //now that the dialog is set up, it's time to show it    
  124.             dialog.show();
  125.  
  126.         }};
  127. }
Advertisement
Add Comment
Please, Sign In to add comment