Androidエッセイ25——検索ボックス入力後のインタフェースの隠しロジック
39390 ワード
xmlファイル
JAvaファイル
<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" android:background="@color/white" tools:context=".Operate" >
<RelativeLayout android:id="@+id/opeate_title" android:layout_width="match_parent" android:layout_height="@dimen/title_height" android:layout_gravity="center_vertical|center_horizontal" android:background="@drawable/top" android:gravity="center_vertical|center_vertical" android:orientation="horizontal" >
<RelativeLayout android:id="@+id/ope_back" android:layout_width="50dp" android:layout_height="fill_parent" android:clickable="true" android:gravity="center" >
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/back" />
</RelativeLayout>
<!-- -->
<TextView android:id="@+id/ope_tv_title" style="@style/titleText" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:text="@string/operate_title" >
</TextView>
</RelativeLayout>
<RelativeLayout android:id="@+id/operate_lay_search" android:layout_width="match_parent" android:layout_height="@dimen/title_height" android:layout_below="@id/opeate_title" android:focusable="true" android:focusableInTouchMode="true" android:orientation="horizontal" >
<EditText android:id="@+id/operate_edit_search" android:layout_width="fill_parent" android:layout_height="35dp" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@drawable/bg_edit_search" android:drawableLeft="@drawable/sy_search" android:hint=" " android:paddingLeft="10dp" />
</RelativeLayout>
<View android:id="@+id/line1" android:layout_width="match_parent" android:layout_height="@dimen/line_height" android:layout_below="@id/operate_lay_search" android:background="@color/line" />
<!-- -->
<LinearLayout android:id="@+id/ope_lay_listcontent_search" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/line1" android:orientation="vertical" android:visibility="gone" >
<ListView android:id="@+id/ope_lv_content_search" android:layout_width="match_parent" android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout android:id="@+id/ope_lay_listcontent" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/operate_btn_more2" android:layout_below="@id/line1" android:orientation="vertical" >
<ListView android:id="@+id/ope_lv_content" android:layout_width="match_parent" android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<Button android:id="@+id/operate_btn_more2" android:layout_width="match_parent" android:layout_height="40dp" android:layout_alignParentBottom="true" android:layout_gravity="center" android:layout_marginBottom="60dip" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="@drawable/login_title" android:text=" " android:textColor="@color/white" />
<LinearLayout android:id="@+id/operate_lay_home" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_gravity="center" android:gravity="bottom" android:orientation="vertical" >
<RadioGroup android:id="@+id/home_radio_group" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:gravity="center_vertical" android:orientation="horizontal" >
<RadioButton android:id="@+id/home_tab_main" style="@style/home_tab_bottom" android:checked="true" android:drawableTop="@drawable/home_main_selector" android:text="@string/menu_shouye" android:textColor="@drawable/text_select" />
<RadioButton android:id="@+id/home_tab_personal" style="@style/home_tab_bottom" android:drawableTop="@drawable/home_personal_selector" android:text="@string/menu_geren" android:textColor="@drawable/text_select" />
</RadioGroup>
</LinearLayout>
</RelativeLayout>
JAvaファイル
package com.xxx.xxx
import java.util.ArrayList;
import java.util.List;
import org.kymjs.aframe.http.KJHttp;
import org.kymjs.aframe.http.KJStringParams;
import org.kymjs.aframe.http.StringCallBack;
import org.kymjs.aframe.ui.BindView;
import org.kymjs.aframe.ui.activity.BaseActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.Toast;
import com.alibaba.fastjson.JSON;
import com.gexun.sunmess_hg.common.CommonDate;
import com.gexun.sunmess_hg.common.HttpUrl;
import com.gexun.sunmess_hg.common.MyConstace;
import com.gexun.sunmess_hg.dataobject.SchoolDto;
import com.gexun.sunmess_hg.dataobject.SchoolMsgDto;
import com.gexun.sunmess_hg.widget.CustomProgressDialog;
/** * 1 2 * */
public class Operate extends BaseActivity {
//
// @BindView(id = R.id.ope_lv_content )
private ListView opeListV;
@BindView(id = R.id.ope_lv_content_search, click = true)
private ListView opeSearchListV;
@BindView(id = R.id.ope_back, click = true)
private View layback;
@BindView(id = R.id.operate_lay_home, click = true)
private View home;
@BindView(id = R.id.operate_btn_more2, click = true)
private View operate_btn_more;
@BindView(id = R.id.operate_edit_search)
private EditText search;
//
@BindView(id = R.id.operate_edit_search, click = true)
private View searchBtn;
@BindView(id = R.id.ope_lay_listcontent_search)
private View searchContent;
@BindView(id = R.id.ope_lay_listcontent)
private View schoolContent;
//
@BindView(id = R.id.home_tab_main , click = true)
private RadioButton home_tab_main;
@BindView(id = R.id.home_tab_personal , click =true)
private RadioButton home_tab_personal;
// @BindView(id = R.id.operate_swiperefresh, click = true)
// private android.support.v4.widget.SwipeRefreshLayout swip;
// @BindView(id = R.id.operate_swiperefresh_search)
// private android.support.v4.widget.SwipeRefreshLayout searchSwip;
private List<SchoolDto> schoolDtoList = new ArrayList<SchoolDto>();
private List<SchoolDto> schoolDtoAllList = new ArrayList<SchoolDto>();
private List<SchoolDto> schoolSearchDtoList = new ArrayList<SchoolDto>();
private List<SchoolDto> schoolSearchDtoAllList = new ArrayList<SchoolDto>();
private com.gexun.sunmess_hg.adapter.ListOperateAdapter ListOperateAdapter;
private com.gexun.sunmess_hg.adapter.ListOperateSearchAdapter ListOperateSearchAdapter;
private CustomProgressDialog dialog;
private int pageNum = 1;// , 1
private String destination ;// : ,
private Intent intent;
@Override
public void setRootView() {
// TODO Auto-generated method stub
requestWindowFeature(Window.FEATURE_NO_TITLE);//
setContentView(R.layout.operate);//
setBackListener(false);
dialog = CustomProgressDialog.createDialog(Operate.this, " ");// dialog
pageNum = 1;//
schoolDtoAllList.clear();// list
destination = getIntent().getStringExtra("destination");// intent
}
@Override
protected void initWidget() {
// TODO Auto-generated method stub
super.initWidget();
// search.setOnClickListener(new View.OnClickListener() {
//
// @Override
// public void onClick(View v) {
// // TODO Auto-generated method stub
// Log.i("zdj","search-onclick");
// searchContent.setVisibility(View.VISIBLE);
// schoolContent.setVisibility(View.GONE);
// home.setVisibility(View.GONE);
// operate_btn_more.setVisibility(View.GONE);
// }
// });
// search.setOnFocusChangeListener(new OnFocusChangeListener() {
//
// @Override
// public void onFocusChange(View v, boolean hasFocus) {
// // TODO Auto-generated method stub
// Log.i("zdj","search-onFocusChange");
// searchContent.setVisibility(View.VISIBLE);
// schoolContent.setVisibility(View.GONE);
// home.setVisibility(View.GONE);
// operate_btn_more.setVisibility(View.GONE);
// }
// });
// initData();
//
// swip.setColorScheme(android.R.color.holo_red_light,
// android.R.color.holo_green_light,
// android.R.color.holo_blue_bright,
// android.R.color.holo_orange_light);
// swip.setOnRefreshListener(new OnRefreshListener() {
//
// @Override
// public void onRefresh() {
// // TODO Auto-generated method stub
//
// pageNum++;
// initData();
// swip.setRefreshing(false);
//
// }
// });
//===================================================================
**//
search.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int arg1, int arg2,
int arg3) {
// Log.i("zdj"," :"+s);
if (s.length() > 0) {
searchContent.setVisibility(View.VISIBLE);
schoolContent.setVisibility(View.GONE);
home.setVisibility(View.GONE);
operate_btn_more.setVisibility(View.GONE);
//
initFuzzySearchData(s.toString());
} else {
searchContent.setVisibility(View.GONE);
schoolContent.setVisibility(View.VISIBLE);
home.setVisibility(View.VISIBLE);
operate_btn_more.setVisibility(View.VISIBLE);
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
}
});
}**
//===================================================================
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
@Override
public void widgetClick(View v) {
// TODO Auto-generated method stub
super.widgetClick(v);
switch (v.getId()) {
case R.id.ope_back://
intent = new Intent(Operate.this, HomeActivity.class);
startActivity(intent);
finish();
break;
case R.id.home_tab_main://
intent = new Intent(Operate.this, HomeActivity.class);
startActivity(intent);
finish();
break;
case R.id.home_tab_personal://
intent = new Intent(Operate.this, PersonalActivity2.class);
startActivity(intent);
finish();
break;
case R.id.operate_btn_more2://
pageNum++;
initData();
break;
case R.id.operate_edit_search://
search.setText("");
break;
default:
break;
}
}
//
public void initData() {
dialog.show();// dialog
SharedPreferences sp = getSharedPreferences(MyConstace.SP_NAME,0);
String schoolName = sp.getString("SCHOOL_NAME","1");
String refectoryName = sp.getString("refectoryName", " ( )");
System.err.println("===================="+schoolName);
KJHttp http = new KJHttp();
KJStringParams params = new KJStringParams();
//
params.put("limit", CommonDate.limit + "");//
params.put("page", pageNum + "");//
// params.put("frefectoryName", schoolName+"");
params.put("frefectoryName", refectoryName+"");
// params.put("frefectoryName", " ( )");
Log.e("aaa", " :" + params.toString());
// params.put("frefectoryName", "--");//
//
http.urlGet(HttpUrl.schoolInfo, params, new StringCallBack() {
@Override
//
public void onSuccess(String str) {
// Log.i("zdj", " :" + str);
System.err.println("=================="+str);
SchoolMsgDto schoolMsgDto = JSON.parseObject(str,
SchoolMsgDto.class);
schoolDtoList = JSON.parseArray(schoolMsgDto.getItems()
.toString(), SchoolDto.class);// Json
if (schoolDtoList != null) {
for (int i = 0; i < schoolDtoList.size(); i++) {
schoolDtoAllList.add(schoolDtoList.get(i));
}
}
opeListV = (ListView) findViewById(R.id.ope_lv_content);
ListOperateAdapter = new com.gexun.sunmess_hg.adapter.ListOperateAdapter(
Operate.this, schoolDtoAllList,destination);
opeListV.setAdapter(ListOperateAdapter);
// dialog.cancel();
dialog.cancel();
}
//
@Override
public void onFailure(Throwable t, int errorNo, String strMsg) {
super.onFailure(t, errorNo, strMsg);
Toast.makeText(Operate.this, " ", 3000).show();
dialog.cancel();
}
});
}
/** * * * @param searchContent * */
public void initFuzzySearchData(String searchContent) {
// dialog.show();
//
schoolSearchDtoAllList.clear();
schoolSearchDtoList.clear();
KJHttp http = new KJHttp();
KJStringParams params = new KJStringParams();
params.put("limit", "0");//
params.put("page", "0");//
//
params.put("frefectoryName", searchContent);//
Log.e("zdj", " :" + params.toString());
//
http.urlGet(HttpUrl.schoolInfo, params, new StringCallBack() {
@Override
//
public void onSuccess(String str) {
// Log.i("zdj", " :" + str);
SchoolMsgDto schoolMsgDto = JSON.parseObject(str,
SchoolMsgDto.class);
schoolSearchDtoList = JSON.parseArray(schoolMsgDto.getItems()
.toString(), SchoolDto.class);
if (schoolSearchDtoList != null) {
for (int i = 0; i < schoolSearchDtoList.size(); i++) {
schoolSearchDtoAllList.add(schoolSearchDtoList.get(i));
}
}
opeSearchListV = (ListView) findViewById(R.id.ope_lv_content_search);
ListOperateSearchAdapter = new com.gexun.sunmess_hg.adapter.ListOperateSearchAdapter(
Operate.this, schoolSearchDtoAllList);
opeSearchListV.setAdapter(ListOperateSearchAdapter);
// dialog.cancel();
}
//
@Override
public void onFailure(Throwable t, int errorNo, String strMsg) {
super.onFailure(t, errorNo, strMsg);
Toast.makeText(Operate.this, " ", 3000).show();
// dialog.cancel();
}
});
}
//
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0) {
//do something...
intent = new Intent(Operate.this, HomeActivity.class);
startActivity(intent);
finish();
return true;// false
}
return super.onKeyDown(keyCode, event);
}
@Override
/** */
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
getMenuInflater().inflate(R.menu.activity_menu1, menu);
return true;
}
@Override
/** */
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.menu_next:
//
Intent i = new Intent(this,GxCemare2.class);
startActivity(i);
finish();
break;
default:
break;
}
return true;
}
}