Android-项目S-017-index_index_school-2020-5-17
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ededed"
android:orientation="vertical">
<LinearLayout
android:id="@+id/app"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#4458a1">
<TextView
android:layout_width="match_parent"
android:layout_height="41dp"
android:background="#4458a1"
android:textColor="#ffffff"
android:text="@string/app_name"
android:layout_marginTop="8dp"
android:layout_marginLeft="15dp"
android:layout_gravity="center"
android:textSize="19dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#4658a4"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="16dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:orientation="horizontal"
android:background="@drawable/index_school_search">
<EditText
android:id="@+id/search"
android:layout_width="220dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:layout_marginRight="10dp"
android:hint="请输入你要查找的地点,联系方式"
android:textSize="14dp"
android:inputType="text"
android:background="#00ffffff"
/>
<View
android:layout_width="2dp"
android:layout_marginLeft="60dp"
android:layout_height="match_parent"
android:background="#ededed" />
<Button
android:id="@+id/bsearch"
style="?android:attr/borderlessButtonStyle"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="0dp"
android:background="@mipmap/index_school_search" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="420dp"
android:layout_marginTop="20dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="15dp"
android:orientation="vertical"
android:background="@drawable/index_school_index">
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- TabWidget组件id值不可变-->
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TabWidget>
<!-- FrameLayout布局,id值不可变-->
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@android:id/tabs">
<!-- 第一个tab的布局 -->
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txtOne"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="未找到此关键词的地点哦!"
android:textColor="#000000"
android:textSize="16.5sp"
android:layout_gravity="center"
android:gravity="center"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<!-- 第二个tab的布局 -->
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txtTwo"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="未找到此关键词的联系方式哦!"
android:textColor="#000000"
android:textSize="16.5sp"
android:layout_gravity="center"
android:gravity="center"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/center_reclycleview"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="match_parent"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
</LinearLayout>
package com.example.bottom_00.ui.index;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.Toast;
import com.example.bottom_00.R;
import com.example.bottom_00.ui.my.my_about;
import com.example.bottom_00.ui.my.my_bind;
import com.example.bottom_00.ui.my.my_newbing_Dialog;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import android.text.TextWatcher;
public class index_school extends AppCompatActivity {
private List<index_school_SchoolPHS_0> PhS1List = new ArrayList<index_school_SchoolPHS_0>();
private List<index_school_Bean.DatasBean> datas = new ArrayList<>();
@BindView(R.id.center_reclycleview)
RecyclerView c_RecyclerView;
private index_school_SchoolPHS_1_RvAdapter mRvAdapter;
private index_school_Bean mBean;
private EditText search;
private Button bsearch;
private TextView txtOne;
private TextView txtTwo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_index_school);
final TabHost tab = (TabHost) findViewById(android.R.id.tabhost);
//初始化TabHost容器
tab.setup();
//在TabHost创建标签,然后设置:标题/图标/标签页布局
tab.addTab(tab.newTabSpec("tab1").setIndicator("场馆时间", null).setContent(R.id.tab1));
tab.addTab(tab.newTabSpec("tab2").setIndicator("联系方式", null).setContent(R.id.tab2));
updateTab(tab);
setA(1);
//标签切换事件处理,setOnTabChangedListener
tab.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
@Override
// tabId是newTabSpec第一个参数设置的tab页名,并不是layout里面的标识符id
public void onTabChanged(String tabId) {
if (tabId.equals("tab1")) { //第一个标签
updateTab(tab);
System.out.println("第一个-------------------------------------------------------------");
}
if (tabId.equals("tab2")) { //第二个标签
System.out.println("第二个-------------------------------------------------------------");
int b=getA();
if(b==1){
index_school_toast.showToast(getApplicationContext(),
0, "点击电话号码可直接拨打哦~");
setA(2);
}
updateTab(tab);}
}
});
bsearch = findViewById(R.id.bsearch);
txtOne=findViewById(R.id.txtOne);
txtTwo=findViewById(R.id.txtTwo);
txtOne.setVisibility(View.GONE);
txtTwo.setVisibility(View.GONE);
bsearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String csearch=search.getText().toString();
System.out.println("点击搜索");
if(search.getText().toString() != null && search.getText().toString() .length() > 0){
getJson1(csearch);
getJson(csearch);
PhS1List.clear();
datas.clear();}
else
{
showDialog();
}
}
});
getJson();
//initFruits();
ButterKnife.bind(this);
getJson1();
search = findViewById(R.id.search);
search.addTextChangedListener(textWatcher);
}
/**
* 显示对话框
*/
private void showDialog() {
index_school_toast_1 dialog = new index_school_toast_1(index_school.this, R.style.mdialog,
new index_school_toast_1.OncloseListener() {
@Override
public void onClick(boolean confirm) {
if (confirm) {
System.out.println("你点了取消");
} else {
System.out.println("你点了取消");
}
}
});
dialog.show();
}
private int a;
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
private TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
//
System.out.println("-1-onTextChanged-->"
+ search.getText().toString() + "<--");
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
//
System.out.println("-2-beforeTextChanged-->"
+ search.getText().toString() + "<--");
}
@Override
public void afterTextChanged(Editable s) {
//
System.out.println("-3-afterTextChanged-->"
+ search.getText().toString() + "<--");
if(search.getText().toString() != null && search.getText().toString() .length() > 0) {
}
else
{
System.out.println("输入框为口");
PhS1List.clear();
datas.clear();
getJson();
getJson1();
}
}
};
public void getJson1() {
txtTwo.setVisibility(View.GONE);
OkHttpClient okhttpClient = new OkHttpClient();
FormBody.Builder formBody = new FormBody.Builder();//创建表单请求体
formBody.add("type", "3");
// formBody.add("password", "1");
Request request = new Request.Builder()
// .url("https://ancientcloud.club/androidphsjson")
.url("https://xxxxxxxn/api/SchoolPHS/getInfo")
.post(formBody.build())
.build();
Call call2 = okhttpClient.newCall(request);
call2.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
// Toast.makeText(index_school.this, "异步post请求数据失败!", Toast.LENGTH_LONG).show();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String res = response.body().string();
runOnUiThread(new Runnable() {
@Override
public void run() {
// Toast.makeText(index_school.this, "post异步请求数据成功!", Toast.LENGTH_LONG).show();
System.out.println(res);
JSONObject obj = null;//最外层的JSONObject对象
try {
obj = new JSONObject(res);
} catch (JSONException e) {
e.printStackTrace();
}
String data= null;//通过name字段获取其所包含的字符串
try {
data = obj.getString("data");
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println("data:"+data);
// JSONArray name= null;//通过name字段获取其所包含的字符串
try {
JSONArray name = new JSONArray(data);
//
mBean = new index_school_Bean();
List<index_school_Bean.DatasBean> datas = new ArrayList<>();
for (int i=0;i<name.length();i++) {
JSONObject object = name.getJSONObject(i);
String jname=object.getString("name");
/* String jtel=object.getString("tel");
String stel= jtel.replaceAll(" ", "\n");*/
/* index_school_SchoolPHS_1 a = new index_school_SchoolPHS_1(jname, stel);
PhS1List1.add(a);*/
String phonenum = object.getString("phonenum");
JSONArray aphonenum = new JSONArray(phonenum);
index_school_Bean.DatasBean datasBean = new index_school_Bean.DatasBean();
List<index_school_Bean.DatasBean.Option> option = new ArrayList<>();
for (int j=0;j<aphonenum.length();j++) {
JSONObject pobj = aphonenum.getJSONObject(j);
String sobj=pobj.toString();
String tel = pobj.getString("tel");
//String stel= tel.replaceAll(",", "\n");
String jtel= tel.replaceAll("\\[", "");
String itel= jtel.replaceAll("]", "");
String ktel= itel.replaceAll("\"", "");
boolean status = sobj.contains("name");
if(status)
{
String tname= pobj.getString("name");
String kname= tname.replaceAll("\n", "");
System.out.println("tel有name"+tel);
System.out.println("name:"+tname);
//json(tel,jname);
boolean status1 = tel.contains(",");
if(status1) {
System.out.println("含有,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
String strq=ktel.substring(0, ktel.indexOf(","));
String strh=ktel.substring(strq.length()+1,ktel.length());
System.out.println("含有,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"+strq);
index_school_Bean.DatasBean.Option optionBean = new index_school_Bean.DatasBean.Option();
optionBean.setDatas(strq);
option.add(optionBean);
index_school_Bean.DatasBean.Option optionBean3 = new index_school_Bean.DatasBean.Option();
optionBean3.setDatas1("\n"+kname);
option.add(optionBean3);
index_school_Bean.DatasBean.Option optionBean1 = new index_school_Bean.DatasBean.Option();
optionBean1.setDatas(strh);
option.add(optionBean1);
index_school_Bean.DatasBean.Option optionBean2 = new index_school_Bean.DatasBean.Option();
optionBean2.setDatas1("");
option.add(optionBean2);
}else {
index_school_Bean.DatasBean.Option optionBean = new index_school_Bean.DatasBean.Option();
optionBean.setDatas(ktel);
option.add(optionBean);
index_school_Bean.DatasBean.Option optionBean1 = new index_school_Bean.DatasBean.Option();
optionBean1.setDatas1(tname);
option.add(optionBean1);
}
}
else
{
System.out.println("tel无name"+tel);
boolean status1 = tel.contains(",");
if(status1) {
System.out.println("含有,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,");
String strq=ktel.substring(0, ktel.indexOf(","));
String strh=ktel.substring(strq.length()+1,ktel.length());
System.out.println("含有,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"+strq);
index_school_Bean.DatasBean.Option optionBean = new index_school_Bean.DatasBean.Option();
optionBean.setDatas(strq);
option.add(optionBean);
index_school_Bean.DatasBean.Option optionBean3 = new index_school_Bean.DatasBean.Option();
optionBean3.setDatas1("");
option.add(optionBean3);
index_school_Bean.DatasBean.Option optionBean1 = new index_school_Bean.DatasBean.Option();
optionBean1.setDatas(strh);
option.add(optionBean1);
index_school_Bean.DatasBean.Option optionBean2 = new index_school_Bean.DatasBean.Option();
optionBean2.setDatas1("");
option.add(optionBean2);
}else {
index_school_Bean.DatasBean.Option optionBean = new index_school_Bean.DatasBean.Option();
optionBean.setDatas(ktel);
option.add(optionBean);
index_school_Bean.DatasBean.Option optionBean1 = new index_school_Bean.DatasBean.Option();
optionBean1.setDatas1("");
option.add(optionBean1);
}
/*
index_school_Bean.DatasBean.Option optionBean = new index_school_Bean.DatasBean.Option();
optionBean.setDatas(ktel);
option.add(optionBean);
index_school_Bean.DatasBean.Option optionBean1 = new index_school_Bean.DatasBean.Option();
optionBean1.setDatas1("");
option.add(optionBean1);
*/
}
}
datasBean.setOptions(option);
datasBean.setTitle(jname);
datas.add(datasBean);
}
mBean.setDatas(datas);
getInfo1();
// getInfo();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
});
}
public void getJson1(String csearch) {
OkHttpClient okhttpClient = new OkHttpClient();
FormBody.Builder formBody = new FormBody.Builder();//创建表单请求体
formBody.add("type", "0");
formBody.add("keywords", csearch);
Request request = new Request.Builder()
// .url("https://ancientcloud.club/androidphsjson")
.url("https://xxxxxxxx/api/SchoolPHS/getInfo")
.post(formBody.build())
.build();
Call call2 = okhttpClient.newCall(request);
call2.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
// Toast.makeText(index_school.this, "异步post请求数据失败!", Toast.LENGTH_LONG).show();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String res = response.body().string();
runOnUiThread(new Runnable() {
@Override
public void run() {
// Toast.makeText(index_school.this, "post异步请求数据成功!", Toast.LENGTH_LONG).show();
System.out.println(res);
JSONObject obj = null;//最外层的JSONObject对象
try {
obj = new JSONObject(res);
} catch (JSONException e) {
e.printStackTrace();
}
String data= null;//通过name字段获取其所包含的字符串
try {
data = obj.getString("data");
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println(data);
if(data.equals("[]"))
{
System.out.println("有");
txtTwo.setVisibility(View.VISIBLE);
}
else
{
System.out.println("无");
}
// JSONArray name= null;//通过name字段获取其所包含的字符串
try {
JSONArray name = new JSONArray(data);
//
mBean = new index_school_Bean();
List<index_school_Bean.DatasBean> datas = new ArrayList<>();
for (int i=0;i<name.length();i++) {
JSONObject object = name.getJSONObject(i);
String jname=object.getString("name");
/* String jtel=object.getString("tel");
String stel= jtel.replaceAll(" ", "\n");*/
/* index_school_SchoolPHS_1 a = new index_school_SchoolPHS_1(jname, stel);
PhS1List1.add(a);*/
String phonenum = object.getString("phonenum");
JSONArray aphonenum = new JSONArray(phonenum);
index_school_Bean.DatasBean datasBean = new index_school_Bean.DatasBean();
List<index_school_Bean.DatasBean.Option> option = new ArrayList<>();
for (int j=0;j<aphonenum.length();j++) {
JSONObject pobj = aphonenum.getJSONObject(j);
String sobj=pobj.toString();
String tel = pobj.getString("tel");
String otel= tel.replaceAll("\\n", "-saasd");
String stel= otel.replaceAll(",", "\n");
String jtel= stel.replaceAll("\\[", "");
String itel= jtel.replaceAll("]", "");
String ktel= itel.replaceAll("\"", "");
boolean status = sobj.contains("name");
if(status)
{
String tname= pobj.getString("name");
System.out.println("tel有name"+tel);
System.out.println("name:"+tname);
//json(tel,jname);
index_school_Bean.DatasBean.Option optionBean = new index_school_Bean.DatasBean.Option();
optionBean.setDatas(ktel);
option.add(optionBean);
index_school_Bean.DatasBean.Option optionBean1 = new index_school_Bean.DatasBean.Option();
optionBean1.setDatas1(tname);
option.add(optionBean1);
}
else
{
System.out.println("tel无name"+tel);
index_school_Bean.DatasBean.Option optionBean = new index_school_Bean.DatasBean.Option();
optionBean.setDatas(ktel);
option.add(optionBean);
index_school_Bean.DatasBean.Option optionBean1 = new index_school_Bean.DatasBean.Option();
optionBean1.setDatas1("");
option.add(optionBean1);
}
}
datasBean.setOptions(option);
datasBean.setTitle(jname);
datas.add(datasBean);
}
mBean.setDatas(datas);
getInfo1();
// getInfo();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
});
}
public void getInfo1()
{
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
c_RecyclerView.setLayoutManager(layoutManager);
c_RecyclerView.setFocusableInTouchMode(false);
mRvAdapter = new index_school_SchoolPHS_1_RvAdapter(this, mBean.getDatas());
c_RecyclerView.setAdapter(mRvAdapter);
mRvAdapter.notifyDataSetChanged();
c_RecyclerView.addItemDecoration(
new HorizontalDividerItemDecoration.Builder(this).build());
}
public void getInfo()
{
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
index_school_SchoolPHS_0_Adapter adapter = new index_school_SchoolPHS_0_Adapter(PhS1List);
recyclerView.setAdapter(adapter);
recyclerView.addItemDecoration(
new HorizontalDividerItemDecoration.Builder(this).build());
}
public void getJson() {
txtOne.setVisibility(View.GONE);
OkHttpClient okhttpClient = new OkHttpClient();
FormBody.Builder formBody = new FormBody.Builder();//创建表单请求体
formBody.add("type", "2");
// formBody.add("password", "1");
Request request = new Request.Builder()
.url("https://xxxxxxxxx/api/SchoolPHS/getInfo")
.post(formBody.build())
.build();
Call call2 = okhttpClient.newCall(request);
call2.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
// Toast.makeText(index_school.this, "异步post请求数据失败!", Toast.LENGTH_LONG).show();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String res = response.body().string();
runOnUiThread(new Runnable() {
@Override
public void run() {
// Toast.makeText(index_school.this, "post异步请求数据成功!", Toast.LENGTH_LONG).show();
System.out.println(res);
JSONObject obj = null;//最外层的JSONObject对象
try {
obj = new JSONObject(res);
} catch (JSONException e) {
e.printStackTrace();
}
String data= null;//通过name字段获取其所包含的字符串
try {
data = obj.getString("data");
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println(data);
// JSONArray name= null;//通过name字段获取其所包含的字符串
try {
JSONArray name = new JSONArray(data);
for (int i=0;i<name.length();i++) {
JSONObject object = name.getJSONObject(i);
String jname=object.getString("name");
String jopening_time=object.getString("opening_time");
String sopening_time= jopening_time.replaceAll(" ", "\n");
String oopening_time=sopening_time.replaceAll("@", " ");
index_school_SchoolPHS_0 a = new index_school_SchoolPHS_0(jname,oopening_time);
PhS1List.add(a);
System.out.println(object);
}
getInfo();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
});
}
public void getJson(String csearch) {
OkHttpClient okhttpClient = new OkHttpClient();
FormBody.Builder formBody = new FormBody.Builder();//创建表单请求体
formBody.add("type", "1");
formBody.add("keywords", csearch);
Request request = new Request.Builder()
.url("https://xxxxxxxx/api/SchoolPHS/getInfo")
.post(formBody.build())
.build();
Call call2 = okhttpClient.newCall(request);
call2.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
// Toast.makeText(index_school.this, "异步post请求数据失败!", Toast.LENGTH_LONG).show();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String res = response.body().string();
runOnUiThread(new Runnable() {
@Override
public void run() {
// Toast.makeText(index_school.this, "post异步请求数据成功!", Toast.LENGTH_LONG).show();
System.out.println(res);
JSONObject obj = null;//最外层的JSONObject对象
try {
obj = new JSONObject(res);
} catch (JSONException e) {
e.printStackTrace();
}
String data= null;//通过name字段获取其所包含的字符串
try {
data = obj.getString("data");
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println(data);
if(data.equals("[]"))
{
System.out.println("有");
txtOne.setVisibility(View.VISIBLE);
}
else
{
System.out.println("无");
}
// JSONArray name= null;//通过name字段获取其所包含的字符串
try {
JSONArray name = new JSONArray(data);
for (int i=0;i<name.length();i++) {
JSONObject object = name.getJSONObject(i);
String jname=object.getString("name");
String jopening_time=object.getString("opening_time");
String sopening_time= jopening_time.replaceAll(" ", "\n");
String oopening_time=sopening_time.replaceAll("@", " ");
index_school_SchoolPHS_0 a = new index_school_SchoolPHS_0(jname,oopening_time);
PhS1List.add(a);
System.out.println(object);
}
getInfo();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
});
}
/**
* 设置一个public方法,供adapter点击事件调用
*
* @param position 为第一层recycleview位置
* @param tag 为第二层recycleview位置
*/
public void OnClickListener(int position, int tag) {
final List<index_school_Bean.DatasBean> datasBeans = mBean.getDatas();
for (int i = 0; i < datasBeans.size(); i++) {
if (i == position) {
List<index_school_Bean.DatasBean.Option> option = datasBeans.get(i).getOptions();
/* for (int j = 0; j < option.size(); j++) {
if (j == tag) {
option.get(j).setSelect(true);
} else {
option.get(j).setSelect(false);
}
}*/
String o=option.get(tag).getDatas();
/* boolean status = o.contains("(");
if(status) {
String str=o.substring(0, o.indexOf("("));
String p=str;
Toast.makeText(MainActivity.this,
datasBeans.get(position).getTitle() + "-" +p ,
Toast.LENGTH_SHORT).show();*/
// }
/*else
{
String p=o;*/
/* Toast.makeText(index_school.this,
datasBeans.get(position).getTitle() + "-" +o,
Toast.LENGTH_SHORT).show();*/
callPhone(o);
// }
} else {
//这里让之前选中的效果还原成未选中
/* List option = datasBeans.get(i).getOptions();
for (int j = 0; j < option.size(); j++) {
option.get(j).setSelect(false);
}*/
}
}
mRvAdapter.notifyDataSetChanged();
}
@SuppressLint("ResourceAsColor")
private void updateTab(final TabHost tabHost) {
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
View view = tabHost.getTabWidget().getChildAt(i);
TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);
tv.setTextSize(16);
if (tabHost.getCurrentTab() == i) {//选中
//view.setBackgroundDrawable(getResources().getDrawable(R.drawable.index_school_select));//选中后的背景
tv.setTextColor(getResources().getColor(R.color.colorAccent));
} else {//不选中
// view.setBackgroundDrawable(getResources().getDrawable(R.drawable.index_school_unselect));//非选择的背景
tv.setTextColor(getResources().getColor(R.color.colorBlack));
}
}
}
public void callPhone(String tel) {
Intent intent = new Intent(Intent.ACTION_DIAL);
Uri data = Uri.parse("tel:" + tel);
intent.setData(data);
startActivity(intent);
}
}