提交 d46e9b34 编写于 作者: C Carson.Ho

add backInterface

上级 bd2b5a93
......@@ -15,6 +15,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SearchDemo">
</activity>
</application>
</manifest>
package scut.carson_ho.search_layout;
import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import scut.carson_ho.searchview.SearchView;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private SearchView searchView;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
searchView = (SearchView) findViewById(R.id.search_layout);
// searchView.setOnClickSearch(new ICallBack() {
// @Override
// public void SearchAciton(String string) {
// System.out.println("我收到了" + string);
// }
// });
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this, SearchDemo.class));
}
});
}
}
package scut.carson_ho.search_layout;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import scut.carson_ho.searchview.ICallBack;
import scut.carson_ho.searchview.SearchView;
import scut.carson_ho.searchview.bCallBack;
/**
* Created by Carson_Ho on 17/8/11.
*/
public class SearchDemo extends AppCompatActivity {
private SearchView searchView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
searchView = (SearchView) findViewById(R.id.search_view);
searchView.setOnClickSearch(new ICallBack() {
@Override
public void SearchAciton(String string) {
System.out.println("我收到了" + string);
}
});
searchView.setOnClickBack(new bCallBack() {
@Override
public void BackAciton() {
finish();
}
});
}
}
\ No newline at end of file
......@@ -4,18 +4,14 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
android:gravity="center"
tools:context="scut.carson_ho.search_layout.MainActivity">
<scut.carson_ho.searchview.SearchView
android:id="@+id/search_layout"
<Button
android:gravity="center"
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:textSizeSearch="5dp"
app:textColorSearch="#3F51B5"
app:textHintSearch="输入查询关键字"
app:searchBlockHeight="150"
app:searchBlockColor="#ffffff"
android:text="点击搜索"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBackground"
tools:context="scut.carson_ho.search_layout.MainActivity">
<scut.carson_ho.searchview.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:textSizeSearch="5dp"
app:textColorSearch="#3F51B5"
app:textHintSearch="输入查询关键字"
app:searchBlockHeight="150"
app:searchBlockColor="#ffffff"
/>
</RelativeLayout>
......@@ -49,6 +49,8 @@ public class SearchView extends LinearLayout {
// 搜索按键回调接口
private ICallBack mCallBack;
// 返回按键回调接口
private bCallBack bCallBack;
// 自定义属性设置
// 1. 搜索字体属性设置:大小、颜色 & 默认提示
......@@ -214,23 +216,21 @@ public class SearchView extends LinearLayout {
}
});
/**
* 点击返回按键后的事件
*/
searchBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 注:由于返回需求会根据自身情况不同而不同,所以具体逻辑由开发者自己实现,此处仅留出接口
if (!(bCallBack == null)){
bCallBack.BackAciton();
}
// // 点击搜索按钮后的事件
// iv_search.setOnClickListener(new OnClickListener() {
// @Override
// public void onClick(View v) {
// boolean hasData = hasData(et_search.getText().toString().trim());
// if (!hasData) {
// insertData(et_search.getText().toString().trim());
//
// //搜索后显示数据库里所有搜索历史是为了测试
// queryData("");
// }
// //根据输入的内容模糊查询商品,并跳转到另一个界面,这个根据需求实现
// Toast.makeText(context, "开始搜索", Toast.LENGTH_SHORT).show();
// System.out.println(et_search.getText());
// }
// });
//根据输入的内容模糊查询商品,并跳转到另一个界面,这个根据需求实现
Toast.makeText(context, "返回到上一页", Toast.LENGTH_SHORT).show();
}
});
}
......@@ -263,6 +263,9 @@ public class SearchView extends LinearLayout {
tv_clear = (TextView) findViewById(R.id.tv_clear);
tv_clear.setVisibility(INVISIBLE);
// 6. 返回按键
searchBack = (ImageView) findViewById(R.id.search_back);
}
......@@ -333,4 +336,12 @@ public class SearchView extends LinearLayout {
this.mCallBack = mCallBack;
}
/**
* 点击返回后的操作,用于接口回调
*/
public void setOnClickBack(bCallBack bCallBack){
this.bCallBack = bCallBack;
}
}
package scut.carson_ho.searchview;
/**
* Created by Carson_Ho on 17/8/11.
*/
public interface bCallBack {
void BackAciton();
}
......@@ -14,6 +14,7 @@
android:paddingRight="10dp"
>
<ImageView
android:id="@+id/search_back"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_gravity="center_vertical"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册