Android Open Source - passby Search Result Activity

From Project

Back to project page passby.


The source code is released under:

Copyright 2014 Firebase, Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ?Software??...

If you think the Android project passby listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

//#CSIT6000B#  Rio He       20227977
//#CSIT6000B#  Cedric Liang 20220395
//#CSIT6000B#  Kevin Wang   20225577 
package com.firebase.client;
//from  w  w  w .j  a  va 2s.c  om
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.firebase.androidchat.*;
import com.firebase.database.User;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

public class SearchResultActivity extends Activity {
  // user inputs room info in LoacteActiviy
  // the info is passed by intent
  private String u_room = new String();

  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    this.u_room = getIntent().getStringExtra("u_room");
    ListView lv = (ListView) findViewById(;
    EditText et = (EditText) findViewById(;
    // init classroom store obj
    RoomInfoDatabase rid = new RoomInfoDatabase();
    // match room info from prev activity
    final ArrayList<String> list = rid.query1room(this.u_room);
        StableArrayAdapter saa = new StableArrayAdapter(SearchResultActivity.this, R.layout.listitem_searchresult, list);
        lv.setOnItemClickListener(new OnItemClickListener() {

      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        String chatRoom = list.get(position);
//        Log.i("chatRoom", chatRoom);
//        Log.i("User.getInstance().getNickname()", User.getInstance().getNickname());
        Intent intent = new Intent(SearchResultActivity.this, MainActivity.class);
        intent.putExtra("chatRoom", chatRoom);
        intent.putExtra("nickname", User.getInstance().getNickname());
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();  
      inflater.inflate(, menu);  
    return true;

  public boolean onOptionsItemSelected(MenuItem item) {
    if(item.getItemId() =={
      Intent intent = new Intent(this, SettingActivity.class);
    return true;
  // ListView Adapter
  private class StableArrayAdapter extends ArrayAdapter<String>{
    private ArrayList<String> list = new ArrayList<String>();
    public StableArrayAdapter(Context context, int textViewResourceId,
        List<String> objects) {
      super(context, textViewResourceId, objects);
      for(int i=0; i<objects.size(); i++){

    public View getView(int position, View convertView, ViewGroup parent) {
      LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View rowView = inflater.inflate(R.layout.listitem_searchresult, parent, false);
      TextView tv = (TextView) rowView.findViewById(;
      return rowView;

  // database to store room info
  private class RoomInfoDatabase{
    private String[] rooms;
    private String notFoundState = new String("Not Found the Room Please Input Again");
    private RoomInfoDatabase(){
    private void initRooms(){
      this.rooms = new String[]{"Academic Building 2464", "Academic Building 2502", "Enterprise Center 4619", "Enterprise Center 4620", "LSK Business Building 1997"};
    // using RegEx to find search result
    public ArrayList<String> query1room(String u_room){
      ArrayList<String> result = new ArrayList<String>();
      Pattern p = Pattern.compile(u_room, Pattern.CASE_INSENSITIVE);
      for(int i=0; i<this.rooms.length; i++){
        Matcher m = p.matcher(this.rooms[i]);
          // not found alert
      return result;

Java Source Code List