Преглед на файлове

1.修改Android Apex Search,增加搜索框。

Pen Li преди 8 години
родител
ревизия
d24e4079f7

+ 64 - 1
Apex Mobile/app/src/main/java/com/usai/apex/SearchListActivity.java

@@ -12,16 +12,19 @@ import android.os.Bundle;
 import android.support.constraint.ConstraintLayout;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.SearchView;
 import android.text.Editable;
 import android.text.InputType;
 import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.view.Gravity;
+import android.view.KeyEvent;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.View.OnClickListener;
+import android.view.inputmethod.EditorInfo;
 import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemSelectedListener;
 import android.widget.ArrayAdapter;
@@ -112,6 +115,12 @@ public class SearchListActivity extends AppCompatActivity implements OnClickList
 //        actionBar.setDisplayShowHomeEnabled(true);
         actionBar.setDisplayShowTitleEnabled(true);
     }
+
+    private EditText mSearchView;
+    private Button mTableExpandBtn;
+    private boolean mShowTable;
+    private SearchListActivity self = this;
+
     @Override
 	protected void onCreate(Bundle savedInstanceState)
 	{
@@ -131,6 +140,7 @@ public class SearchListActivity extends AppCompatActivity implements OnClickList
 //		actionBar.setHomeActionContentDescription("Return");
 ////		actionBar.setDisplayShowTitleEnabled(true);
 //
+		mShowTable = false;
 
 		user = ApexTrackingApplication.get_user();
 
@@ -140,7 +150,7 @@ public class SearchListActivity extends AppCompatActivity implements OnClickList
 		setTitle(getIntent().getStringExtra("title"));
 
 		ll_list = (LinearLayout) findViewById(R.id.ll_list);
-		Button btnok = (Button) findViewById(R.id.btnok);
+		final Button btnok = (Button) findViewById(R.id.btnok);
 		btnok.setOnClickListener(this);
 		Button btncancel = (Button) findViewById(R.id.btncancel);
 		btncancel.setOnClickListener(this);
@@ -150,8 +160,48 @@ public class SearchListActivity extends AppCompatActivity implements OnClickList
 		{
 			hashMap = (HashMap<String, String>) savedInstanceState
 					.getSerializable("hashMap");
+			mShowTable = savedInstanceState.getBoolean("show_table");
 		}
 
+
+		mSearchView = findViewById(R.id.search_view);
+		mSearchView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
+			@Override
+			public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+				if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_UNSPECIFIED) { {
+
+					self.onClick(btnok);
+
+					return true;
+				}}
+				return false;
+			}
+		});
+
+		mTableExpandBtn = findViewById(R.id.search_table_expand_btn);
+		mTableExpandBtn.setOnClickListener(new OnClickListener() {
+			@Override
+			public void onClick(View v) {
+				boolean show = (boolean) v.getTag();
+				mShowTable = !show;
+				v.setTag(mShowTable);
+				if (mShowTable) {
+					mTableExpandBtn.setText("Hide");
+				} else {
+					mTableExpandBtn.setText("Show");
+				}
+				init();
+
+			}
+		});
+
+		if (mShowTable) {
+			mTableExpandBtn.setText("Hide");
+		} else {
+			mTableExpandBtn.setText("Show");
+		}
+		mTableExpandBtn.setTag(mShowTable);
+
 	}
 
 	@Override
@@ -165,6 +215,12 @@ public class SearchListActivity extends AppCompatActivity implements OnClickList
 	{
 		// hashMap.clear();
 		ll_list.removeAllViews();
+
+		if (!mShowTable) {
+			hashMap.clear();
+			return;
+		}
+
 		SQLiteDatabase db = dbUtil.OpenDB(this, null, true);
 		Cursor cursor = db.query("fields_info", new String[] { "aname",
 				"field_type", "name", "_id" }, "function_name='"
@@ -444,6 +500,7 @@ public class SearchListActivity extends AppCompatActivity implements OnClickList
 	@Override
 	protected void onSaveInstanceState(Bundle outState)
 	{
+		outState.putBoolean("show_table",mShowTable);
 		outState.putSerializable("hashmap", hashMap);
 		super.onSaveInstanceState(outState);
 	}
@@ -528,6 +585,12 @@ public class SearchListActivity extends AppCompatActivity implements OnClickList
 				// criterion = parms.toString();
 				// }
 
+				CharSequence keywordChar = mSearchView.getText();
+				if (keywordChar != null) {
+					String keyword = keywordChar.toString();
+					parms.putString("keyword",keyword);
+				}
+
 				parms.putString("module_name", function_name);
 				parms.putString("columns",
 						dbUtil.get_fields(user, function_name));

+ 35 - 4
Apex Mobile/app/src/main/res/layout/activity_search_list.xml

@@ -1,13 +1,44 @@
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    tools:context=".SearchListActivity" >
+                xmlns:tools="http://schemas.android.com/tools"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                xmlns:app="http://schemas.android.com/apk/res-auto"
+                tools:context=".SearchListActivity">
+
+    <LinearLayout
+        android:id="@+id/search_tool_bar"
+        android:layout_width="match_parent"
+        android:layout_height="56dp"
+        android:orientation="horizontal"
+        >
+
+        <EditText
+            android:id="@+id/search_view"
+            android:layout_width="0dp"
+            android:layout_height="match_parent"
+            android:layout_weight="1"
+            android:layout_margin="5dp"
+            android:hint="Keyword"
+            android:imeOptions="actionSearch"
+            android:singleLine="true"
+            android:maxLines="1"
+            />
+
+        <Button
+            android:id="@+id/search_table_expand_btn"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:background="@drawable/bg_button"
+            android:text="Show"
+            android:textAllCaps="false"/>
+
+    </LinearLayout>
 
     <ScrollView
         android:id="@+id/scrollView1"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
+        android:layout_below="@id/search_tool_bar"
         android:layout_above="@+id/foot" >
 
         <LinearLayout