public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final String participant = chatClientInterface.getParticipantNames(getContentResolver())[position]; if (participant.charAt(participant.length() - 2) == 'N') { new AlertDialog.Builder(ParticipantsActivity.this) .setTitle("Create Contact") .setMessage( "Create contact for " + participant.substring(0, participant.length() - 4) + " ?") .setPositiveButton( android.R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { addContact(participant.substring(0, participant.length() - 4)); Context context = getApplicationContext(); CharSequence text = "Contact created!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); finish(); } }) .setNegativeButton( android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); } }) .setIcon(android.R.drawable.ic_dialog_alert) .show(); } else { finish(); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle extras = getIntent().getExtras(); if (extras != null) { nickname = extras.getString("nickname"); } try { chatClientInterface = MicroRuntime.getAgent(nickname).getO2AInterface(ChatClientInterface.class); } catch (StaleProxyException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ControllerException e) { // TODO Auto-generated catch block e.printStackTrace(); } myReceiver = new MyReceiver(); IntentFilter refreshParticipantsFilter = new IntentFilter(); refreshParticipantsFilter.addAction("jade.demo.chat.REFRESH_PARTICIPANTS"); registerReceiver(myReceiver, refreshParticipantsFilter); setContentView(R.layout.participants); setListAdapter( new ArrayAdapter<String>( this, R.layout.participant, chatClientInterface.getParticipantNames())); ListView listView = getListView(); listView.setTextFilterEnabled(true); listView.setOnItemClickListener(listViewtListener); }