├── Android └── SearchExample │ ├── .gitignore │ ├── .idea │ ├── .name │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── encodings.xml │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ ├── runConfigurations.xml │ └── vcs.xml │ ├── SearchExample.iml │ ├── app │ ├── .gitignore │ ├── app.iml │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── androidcss │ │ │ └── searchexample │ │ │ └── ApplicationTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── androidcss │ │ │ │ └── searchexample │ │ │ │ ├── AdapterFish.java │ │ │ │ ├── DataFish.java │ │ │ │ └── MainActivity.java │ │ └── res │ │ │ ├── layout │ │ │ ├── activity_main.xml │ │ │ └── container_fish.xml │ │ │ ├── menu │ │ │ └── search_main.xml │ │ │ ├── mipmap-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ └── dimens.xml │ │ │ ├── values │ │ │ ├── colors.xml │ │ │ ├── dimens.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ │ └── xml │ │ │ └── searchable.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── androidcss │ │ └── searchexample │ │ └── ExampleUnitTest.java │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── MySQL └── tbl_fish.sql ├── PHP ├── config.inc.php └── fish-search.php ├── README.md └── screenshot └── android-search-view-with-php-and-mysql.jpg /Android/SearchExample/.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | /captures 8 | -------------------------------------------------------------------------------- /Android/SearchExample/.idea/.name: -------------------------------------------------------------------------------- 1 | Search Example -------------------------------------------------------------------------------- /Android/SearchExample/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Android/SearchExample/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Android/SearchExample/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Android/SearchExample/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /Android/SearchExample/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /Android/SearchExample/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Android/SearchExample/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /Android/SearchExample/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Android/SearchExample/SearchExample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Android/SearchExample/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /Android/SearchExample/app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /Android/SearchExample/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.androidcss.searchexample" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.3.0' 26 | compile 'com.android.support:recyclerview-v7:23.3.0' 27 | } 28 | -------------------------------------------------------------------------------- /Android/SearchExample/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\gururaj\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/androidTest/java/com/androidcss/searchexample/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.androidcss.searchexample; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/java/com/androidcss/searchexample/AdapterFish.java: -------------------------------------------------------------------------------- 1 | package com.androidcss.searchexample; 2 | 3 | import android.content.Context; 4 | import android.support.v4.content.ContextCompat; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.TextView; 10 | import android.widget.Toast; 11 | import java.util.Collections; 12 | import java.util.List; 13 | 14 | public class AdapterFish extends RecyclerView.Adapter { 15 | 16 | private Context context; 17 | private LayoutInflater inflater; 18 | List data= Collections.emptyList(); 19 | DataFish current; 20 | int currentPos=0; 21 | 22 | // create constructor to initialize context and data sent from MainActivity 23 | public AdapterFish(Context context, List data){ 24 | this.context=context; 25 | inflater= LayoutInflater.from(context); 26 | this.data=data; 27 | } 28 | 29 | // Inflate the layout when ViewHolder created 30 | @Override 31 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 32 | View view=inflater.inflate(R.layout.container_fish, parent,false); 33 | MyHolder holder=new MyHolder(view); 34 | return holder; 35 | } 36 | 37 | // Bind data 38 | @Override 39 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 40 | 41 | // Get current position of item in RecyclerView to bind data and assign values from list 42 | MyHolder myHolder= (MyHolder) holder; 43 | DataFish current=data.get(position); 44 | myHolder.textFishName.setText(current.fishName); 45 | myHolder.textSize.setText("Size: " + current.sizeName); 46 | myHolder.textType.setText("Category: " + current.catName); 47 | myHolder.textPrice.setText("Rs. " + current.price + "\\Kg"); 48 | myHolder.textPrice.setTextColor(ContextCompat.getColor(context, R.color.colorAccent)); 49 | 50 | } 51 | 52 | // return total item from List 53 | @Override 54 | public int getItemCount() { 55 | return data.size(); 56 | } 57 | 58 | 59 | class MyHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ 60 | 61 | TextView textFishName; 62 | TextView textSize; 63 | TextView textType; 64 | TextView textPrice; 65 | 66 | // create constructor to get widget reference 67 | public MyHolder(View itemView) { 68 | super(itemView); 69 | textFishName= (TextView) itemView.findViewById(R.id.textFishName); 70 | textSize = (TextView) itemView.findViewById(R.id.textSize); 71 | textType = (TextView) itemView.findViewById(R.id.textType); 72 | textPrice = (TextView) itemView.findViewById(R.id.textPrice); 73 | itemView.setOnClickListener(this); 74 | } 75 | 76 | // Click event for all items 77 | @Override 78 | public void onClick(View v) { 79 | 80 | Toast.makeText(context, "You clicked an item", Toast.LENGTH_SHORT).show(); 81 | 82 | } 83 | 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/java/com/androidcss/searchexample/DataFish.java: -------------------------------------------------------------------------------- 1 | package com.androidcss.searchexample; 2 | 3 | public class DataFish { 4 | public String fishName; 5 | public String catName; 6 | public String sizeName; 7 | public int price; 8 | } 9 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/java/com/androidcss/searchexample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.androidcss.searchexample; 2 | 3 | import android.app.ProgressDialog; 4 | import android.app.SearchManager; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.net.Uri; 8 | import android.os.AsyncTask; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.os.Bundle; 11 | import android.support.v7.widget.LinearLayoutManager; 12 | import android.support.v7.widget.RecyclerView; 13 | import android.support.v7.widget.SearchView; 14 | import android.view.Menu; 15 | import android.view.MenuItem; 16 | import android.widget.Toast; 17 | import org.json.JSONArray; 18 | import org.json.JSONException; 19 | import org.json.JSONObject; 20 | import java.io.BufferedReader; 21 | import java.io.BufferedWriter; 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | import java.io.InputStreamReader; 25 | import java.io.OutputStream; 26 | import java.io.OutputStreamWriter; 27 | import java.net.HttpURLConnection; 28 | import java.net.MalformedURLException; 29 | import java.net.URL; 30 | import java.util.ArrayList; 31 | import java.util.List; 32 | 33 | public class MainActivity extends AppCompatActivity { 34 | 35 | // CONNECTION_TIMEOUT and READ_TIMEOUT are in milliseconds 36 | public static final int CONNECTION_TIMEOUT = 10000; 37 | public static final int READ_TIMEOUT = 15000; 38 | private RecyclerView mRVFish; 39 | private AdapterFish mAdapter; 40 | 41 | SearchView searchView = null; 42 | 43 | 44 | @Override 45 | protected void onCreate(Bundle savedInstanceState) { 46 | super.onCreate(savedInstanceState); 47 | setContentView(R.layout.activity_main); 48 | } 49 | 50 | @Override 51 | public boolean onCreateOptionsMenu(Menu menu) { 52 | 53 | // adds item to action bar 54 | getMenuInflater().inflate(R.menu.search_main, menu); 55 | 56 | // Get Search item from action bar and Get Search service 57 | MenuItem searchItem = menu.findItem(R.id.action_search); 58 | SearchManager searchManager = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE); 59 | if (searchItem != null) { 60 | searchView = (SearchView) searchItem.getActionView(); 61 | } 62 | if (searchView != null) { 63 | searchView.setSearchableInfo(searchManager.getSearchableInfo(MainActivity.this.getComponentName())); 64 | searchView.setIconified(false); 65 | } 66 | 67 | return true; 68 | } 69 | 70 | @Override 71 | public boolean onOptionsItemSelected(MenuItem item) { 72 | 73 | return super.onOptionsItemSelected(item); 74 | } 75 | 76 | // Every time when you press search button on keypad an Activity is recreated which in turn calls this function 77 | @Override 78 | protected void onNewIntent(Intent intent) { 79 | // Get search query and create object of class AsyncFetch 80 | if (Intent.ACTION_SEARCH.equals(intent.getAction())) { 81 | String query = intent.getStringExtra(SearchManager.QUERY); 82 | if (searchView != null) { 83 | searchView.clearFocus(); 84 | } 85 | new AsyncFetch(query).execute(); 86 | 87 | } 88 | } 89 | 90 | // Create class AsyncFetch 91 | private class AsyncFetch extends AsyncTask { 92 | 93 | ProgressDialog pdLoading = new ProgressDialog(MainActivity.this); 94 | HttpURLConnection conn; 95 | URL url = null; 96 | String searchQuery; 97 | 98 | public AsyncFetch(String searchQuery){ 99 | this.searchQuery=searchQuery; 100 | } 101 | 102 | @Override 103 | protected void onPreExecute() { 104 | super.onPreExecute(); 105 | 106 | //this method will be running on UI thread 107 | pdLoading.setMessage("\tLoading..."); 108 | pdLoading.setCancelable(false); 109 | pdLoading.show(); 110 | 111 | } 112 | 113 | @Override 114 | protected String doInBackground(String... params) { 115 | try { 116 | 117 | // Enter URL address where your php file resides 118 | url = new URL("http://192.168.1.7/test/fish-search.php"); 119 | 120 | } catch (MalformedURLException e) { 121 | // TODO Auto-generated catch block 122 | e.printStackTrace(); 123 | return e.toString(); 124 | } 125 | try { 126 | 127 | // Setup HttpURLConnection class to send and receive data from php and mysql 128 | conn = (HttpURLConnection) url.openConnection(); 129 | conn.setReadTimeout(READ_TIMEOUT); 130 | conn.setConnectTimeout(CONNECTION_TIMEOUT); 131 | conn.setRequestMethod("POST"); 132 | 133 | // setDoInput and setDoOutput to true as we send and recieve data 134 | conn.setDoInput(true); 135 | conn.setDoOutput(true); 136 | 137 | // add parameter to our above url 138 | Uri.Builder builder = new Uri.Builder().appendQueryParameter("searchQuery", searchQuery); 139 | String query = builder.build().getEncodedQuery(); 140 | 141 | OutputStream os = conn.getOutputStream(); 142 | BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); 143 | writer.write(query); 144 | writer.flush(); 145 | writer.close(); 146 | os.close(); 147 | conn.connect(); 148 | 149 | } catch (IOException e1) { 150 | // TODO Auto-generated catch block 151 | e1.printStackTrace(); 152 | return e1.toString(); 153 | } 154 | 155 | try { 156 | 157 | int response_code = conn.getResponseCode(); 158 | 159 | // Check if successful connection made 160 | if (response_code == HttpURLConnection.HTTP_OK) { 161 | 162 | // Read data sent from server 163 | InputStream input = conn.getInputStream(); 164 | BufferedReader reader = new BufferedReader(new InputStreamReader(input)); 165 | StringBuilder result = new StringBuilder(); 166 | String line; 167 | 168 | while ((line = reader.readLine()) != null) { 169 | result.append(line); 170 | } 171 | 172 | // Pass data to onPostExecute method 173 | return (result.toString()); 174 | 175 | } else { 176 | return("Connection error"); 177 | } 178 | 179 | } catch (IOException e) { 180 | e.printStackTrace(); 181 | return e.toString(); 182 | } finally { 183 | conn.disconnect(); 184 | } 185 | 186 | 187 | } 188 | 189 | @Override 190 | protected void onPostExecute(String result) { 191 | 192 | //this method will be running on UI thread 193 | pdLoading.dismiss(); 194 | List data=new ArrayList<>(); 195 | 196 | pdLoading.dismiss(); 197 | if(result.equals("no rows")) { 198 | Toast.makeText(MainActivity.this, "No Results found for entered query", Toast.LENGTH_LONG).show(); 199 | }else{ 200 | 201 | try { 202 | 203 | JSONArray jArray = new JSONArray(result); 204 | 205 | // Extract data from json and store into ArrayList as class objects 206 | for (int i = 0; i < jArray.length(); i++) { 207 | JSONObject json_data = jArray.getJSONObject(i); 208 | DataFish fishData = new DataFish(); 209 | fishData.fishName = json_data.getString("fish_name"); 210 | fishData.catName = json_data.getString("cat_name"); 211 | fishData.sizeName = json_data.getString("size_name"); 212 | fishData.price = json_data.getInt("price"); 213 | data.add(fishData); 214 | } 215 | 216 | // Setup and Handover data to recyclerview 217 | mRVFish = (RecyclerView) findViewById(R.id.fishPriceList); 218 | mAdapter = new AdapterFish(MainActivity.this, data); 219 | mRVFish.setAdapter(mAdapter); 220 | mRVFish.setLayoutManager(new LinearLayoutManager(MainActivity.this)); 221 | 222 | } catch (JSONException e) { 223 | // You to understand what actually error is and handle it appropriately 224 | Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_LONG).show(); 225 | Toast.makeText(MainActivity.this, result.toString(), Toast.LENGTH_LONG).show(); 226 | } 227 | 228 | } 229 | 230 | } 231 | 232 | } 233 | } -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 13 | 14 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/layout/container_fish.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 28 | 29 | 38 | 39 | 48 | 49 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/menu/search_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidcss/android-search-view-with-php-and-mysql/0a3069a9b32a338ca1c0e0f10daaf2242cea49be/Android/SearchExample/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidcss/android-search-view-with-php-and-mysql/0a3069a9b32a338ca1c0e0f10daaf2242cea49be/Android/SearchExample/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidcss/android-search-view-with-php-and-mysql/0a3069a9b32a338ca1c0e0f10daaf2242cea49be/Android/SearchExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidcss/android-search-view-with-php-and-mysql/0a3069a9b32a338ca1c0e0f10daaf2242cea49be/Android/SearchExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidcss/android-search-view-with-php-and-mysql/0a3069a9b32a338ca1c0e0f10daaf2242cea49be/Android/SearchExample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Search Example 3 | 4 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/main/res/xml/searchable.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Android/SearchExample/app/src/test/java/com/androidcss/searchexample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.androidcss.searchexample; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /Android/SearchExample/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.3.0' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | jcenter() 18 | } 19 | } 20 | 21 | task clean(type: Delete) { 22 | delete rootProject.buildDir 23 | } 24 | -------------------------------------------------------------------------------- /Android/SearchExample/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /Android/SearchExample/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidcss/android-search-view-with-php-and-mysql/0a3069a9b32a338ca1c0e0f10daaf2242cea49be/Android/SearchExample/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /Android/SearchExample/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu May 12 13:21:40 IST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip 7 | -------------------------------------------------------------------------------- /Android/SearchExample/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /Android/SearchExample/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /Android/SearchExample/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /MySQL/tbl_fish.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 4.1.14 3 | -- http://www.phpmyadmin.net 4 | -- 5 | -- Host: 127.0.0.1 6 | -- Generation Time: May 14, 2016 at 09:23 AM 7 | -- Server version: 5.6.17 8 | -- PHP Version: 5.5.12 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | SET time_zone = "+00:00"; 12 | 13 | 14 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 15 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 16 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 17 | /*!40101 SET NAMES utf8 */; 18 | 19 | -- 20 | -- Database: `test` 21 | -- 22 | 23 | -- -------------------------------------------------------- 24 | 25 | -- 26 | -- Table structure for table `tbl_fish` 27 | -- 28 | 29 | CREATE TABLE IF NOT EXISTS `tbl_fish` ( 30 | `fish_id` int(11) NOT NULL AUTO_INCREMENT, 31 | `fish_name` varchar(255) NOT NULL, 32 | `cat_name` varchar(50) NOT NULL, 33 | `size_name` varchar(50) NOT NULL, 34 | `price` int(11) NOT NULL, 35 | KEY `fish_id` (`fish_id`), 36 | FULLTEXT KEY `my_index` (`fish_name`,`cat_name`,`size_name`) 37 | ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; 38 | 39 | -- 40 | -- Dumping data for table `tbl_fish` 41 | -- 42 | 43 | INSERT INTO `tbl_fish` (`fish_id`, `fish_name`, `cat_name`, `size_name`, `price`) VALUES 44 | (1, 'Indian Mackerel', 'Marine Fish', 'Medium', 100), 45 | (2, 'Manthal Repti', 'Marine Fish', 'Small', 200), 46 | (3, 'Baby Sole Fish', 'Marine Fish', 'Medium', 300), 47 | (6, 'Clam Meat', 'Shell Fish', 'Medium', 150), 48 | (7, 'Indian Prawn', 'Shell Fish', 'Medium', 500); 49 | 50 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 51 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 52 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 53 | -------------------------------------------------------------------------------- /PHP/config.inc.php: -------------------------------------------------------------------------------- 1 | setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 11 | } 12 | catch(PDOException $e) 13 | { 14 | die("OOPs something went wrong"); 15 | } 16 | 17 | ?> -------------------------------------------------------------------------------- /PHP/fish-search.php: -------------------------------------------------------------------------------- 1 | prepare($sql); 9 | $statement->bindParam(':search_query', $search_query, PDO::PARAM_STR); 10 | $statement->execute(); 11 | if($statement->rowCount()) 12 | { 13 | $row_all = $statement->fetchall(PDO::FETCH_ASSOC); 14 | header('Content-type: application/json'); 15 | echo json_encode($row_all); 16 | 17 | } 18 | elseif(!$statement->rowCount()) 19 | { 20 | echo "no rows"; 21 | } 22 | } 23 | 24 | ?> 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Search View with PHP and MySQL 2 | 3 | ![screenshot](screenshot/android-search-view-with-php-and-mysql.jpg) 4 | 5 | This tutorial demonstrates how to deal with search view in android using PHP as server side scripting language and MySQL as backend. For Tutorial http://androidcss.com/android/android-search-view-php-mysql/ 6 | -------------------------------------------------------------------------------- /screenshot/android-search-view-with-php-and-mysql.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/androidcss/android-search-view-with-php-and-mysql/0a3069a9b32a338ca1c0e0f10daaf2242cea49be/screenshot/android-search-view-with-php-and-mysql.jpg --------------------------------------------------------------------------------