Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.mydbtest;
- import android.app.Activity;
- import android.app.Dialog;
- import android.content.Intent;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.net.Uri;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.AutoCompleteTextView;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.ListAdapter;
- import android.widget.ListView;
- import android.widget.SimpleCursorAdapter;
- import android.widget.TextView;
- import android.widget.Toast;
- public class EmployeeList extends Activity {
- protected SQLiteDatabase db;
- Cursor cursor, autocursor;
- protected ListAdapter adapter;
- protected ListView employeeList;
- AutoCompleteTextView searchText;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- db = (new DatabaseHelper(this)).getWritableDatabase();
- //searchText = (EditText) findViewById (R.id.searchText);
- employeeList = (ListView) findViewById (R.id.list);
- cursor = db.rawQuery("SELECT _id, member_name, title FROM employee", null);
- adapter = new SimpleCursorAdapter(
- this,
- R.layout.employee_list_item,
- cursor,
- new String[] {"member_name","title"},
- new int[] {R.id.member_name, R.id.title});
- employeeList.setAdapter(adapter);
- employeeList.setOnItemClickListener(listContentOnItemClickListener);
- }
- private ListView.OnItemClickListener listContentOnItemClickListener = new ListView.OnItemClickListener(){
- public void onItemClick(AdapterView<?> parent, View view, int position, long id)
- {
- autocursor = (Cursor) parent.getItemAtPosition(position);
- Log.i("cursor", autocursor.toString());
- String item_content1 = autocursor.getString(autocursor.getColumnIndexOrThrow(DatabaseHelper.MEMBER_NAME));
- String item_content2 = autocursor.getString(autocursor.getColumnIndex(DatabaseHelper.TITLE));
- String item_content3 = autocursor.getString(autocursor.getColumnIndex(DatabaseHelper.OFFICEPHONE));
- final String item_content4 = autocursor.getString(autocursor.getColumnIndex(DatabaseHelper.CELLPHONE));
- final String item_content5 = autocursor.getString(autocursor.getColumnIndex(DatabaseHelper.EMAIL));
- Dialog dialog = new Dialog(EmployeeList.this);
- dialog.setContentView(R.layout.dialog);
- dialog.setTitle(item_content1);
- dialog.setCancelable(true);
- //set up text
- TextView text = (TextView) dialog.findViewById(R.id.TextView01);
- text.setText(item_content2 + item_content3 + item_content4 + item_content5);
- //set up image view
- ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
- img.setImageResource(R.drawable.ic_launcher);
- Toast.makeText(getBaseContext(), "Click", Toast.LENGTH_LONG).show();
- Button call = (Button) dialog.findViewById(R.id.Call);
- Button sms = (Button) dialog.findViewById(R.id.SMS);
- Button email = (Button) dialog.findViewById(R.id.Email);
- call.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent callIntent = new Intent(Intent.ACTION_CALL);
- callIntent.setData(Uri.parse("tel:"+item_content4));
- startActivity(callIntent);
- }
- });
- sms.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- Intent smsIntent = new Intent(Intent.ACTION_VIEW);
- smsIntent.setData(Uri.parse("sms:"+item_content4));
- startActivity(smsIntent);
- }
- });
- email.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View arg0) {
- // TODO Auto-generated method stub
- Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
- String aEmailList[] = { item_content5 };
- emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
- emailIntent.setType("plain/text");
- startActivity(emailIntent);
- }
- });
- //now that the dialog is set up, it's time to show it
- dialog.show();
- }};
- }
Advertisement
Add Comment
Please, Sign In to add comment