<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:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:background="@null"
        >
        <ImageView
            android:id="@+id/search_back"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="15dp"
            android:src="@drawable/liebiao" />
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="20dp"
            android:layout_toLeftOf="@id/main_selector"
            android:layout_toRightOf="@id/search_back"
            android:focusable="true"
            android:focusableInTouchMode="true">
            <ImageView
                android:id="@+id/relation_search"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="9dp" />
            <View
                android:id="@+id/search_line"
                android:layout_width="0.5dp"
                android:layout_height="20dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/relation_search"
                android:background="#fff"></View>

            <EditText
                android:id="@+id/main_et"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/search_line"
                android:background="@null"
                android:hint="八维书城"
                android:textSize="24sp" />
        </RelativeLayout>
        <ImageView
            android:id="@+id/main_selector"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="15dp"
            android:textSize="14sp"
            android:src="@drawable/select"
            />
    </RelativeLayout>
    <TextView
        android:paddingTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="大家都在搜"
        android:textSize="20sp"
        />
    <com.example.library.AutoFlowLayout
        android:id="@+id/main_af"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:paddingTop="10dp"
        >
    </com.example.library.AutoFlowLayout>
    <Button
        android:id="@+id/main_remove"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="点击缩回"/>
    <ListView
        android:id="@+id/search_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>

</LinearLayout>

import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.main_et)
    EditText mainEt;
    @BindView(R.id.main_af)
    AutoFlowLayout mainAf;
    @BindView(R.id.search_list)
    ListView searchList;
    ArrayList<String> content;
    TextView tjText;
    @BindView(R.id.main_remove)
    Button mainRemove;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        content = new ArrayList<String>(){};
        content.add("小说");
        content.add("日本");
        content.add("历史");
        content.add("外国文学");
        content.add("文学");
        content.add("漫画");
        content.add("中国");
        content.add("心理学");
        content.add("随笔");
        content.add("哲学");
        content.add("中国文学");
        content.add("绘本");
        content.add("推理");
        content.add("美国");
        content.add("爱情");
        auto();
    }
    private void auto() {

        mainAf.setAdapter(new FlowAdapter(content) {
            @Override
            public View getView(int i) {
                View view = View.inflate(MainActivity.this, R.layout.text_layout, null);
                tjText = view.findViewById(R.id.tj_text);
                tjText.setText(content.get(i));
                tjText.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        String s1 = mainEt.getText().toString();
                        Toast.makeText(MainActivity.this, s1 + "", Toast.LENGTH_SHORT).show();
                        Intent intent = new Intent(MainActivity.this, ShowActivity.class);
                        intent.putExtra("s1", s1);
                        startActivity(intent);
                    }
                });
                return view;
            }
        });
    }

    @OnClick({R.id.main_remove,R.id.main_selector})
    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.main_remove:
                mainAf.removeAllViews();
                break;
            case R.id.main_selector:
                String s1 = mainEt.getText().toString();
                if (s1 != null && !s1.equals("")) {

                    content.add(s1);
                    auto();
                    content.clear();
                    Intent intent = new Intent(MainActivity.this, ShowActivity.class);
                    intent.putExtra("s1", s1);
                    startActivity(intent);
                } else {
                    Toast.makeText(this, "请在输入框输入您想搜索的商品", Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }
}

public class HttpUtils {

    public final Api apiClient;
    private HttpUtils(){
        OkHttpClient okHttpClient = new OkHttpClient.Builder().addNetworkInterceptor(new LoggingInterceptor()).build();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Constants.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        apiClient = retrofit.create(Api.class);
    }
    public class LoggingInterceptor implements Interceptor {
        @Override public Response intercept(Interceptor.Chain chain) throws IOException {
            Request request = chain.request();
            long t1 = System.nanoTime();
     //   Logger.info(String.format("Sending request %s on %s%n%s",
       //         request.url(), chain.connection(), request.headers()));

            Response response = chain.proceed(request);

            long t2 = System.nanoTime();
//           logger.info(String.format("Received response for %s in %.1fms%n%s",
//                  response.request().url(), (t2 - t1) / 1e6d, response.headers()));

            return response;
        }
    }
    private static class GetHttpUtilsInstance{
        private static HttpUtils httpUtils = new HttpUtils();
    }
    public static HttpUtils getHttpUtilsInstance(){
        return  GetHttpUtilsInstance.httpUtils;
    }
}

 

 

 

 

 

 

 

public class HttpUtils {

    public final Api apiClient;
    private HttpUtils(){
        OkHttpClient okHttpClient = new OkHttpClient.Builder().addNetworkInterceptor(new LoggingInterceptor()).build();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Constants.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        apiClient = retrofit.create(Api.class);
    }
    public class LoggingInterceptor implements Interceptor {
        @Override public Response intercept(Interceptor.Chain chain) throws IOException {
            Request request = chain.request();
            long t1 = System.nanoTime();
     //   Logger.info(String.format("Sending request %s on %s%n%s",
       //         request.url(), chain.connection(), request.headers()));

            Response response = chain.proceed(request);

            long t2 = System.nanoTime();
//           logger.info(String.format("Received response for %s in %.1fms%n%s",
//                  response.request().url(), (t2 - t1) / 1e6d, response.headers()));

            return response;
        }
    }
    private static class GetHttpUtilsInstance{
        private static HttpUtils httpUtils = new HttpUtils();
    }
    public static HttpUtils getHttpUtilsInstance(){
        return  GetHttpUtilsInstance.httpUtils;
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值