淘宝搜索

1.搜索页面

public class MessageFragmentFragment extends BaseFragment<MessageFragmentPresenter> implements MessageFragmentContract.View {

    @BindView(R.id.edit_guanjianzi)
    EditText editGuanjianzi;
    @BindView(R.id.btn_sousuo)
    Button btnSousuo;
    @BindView(R.id.rece_shoplie)
    RecyclerView receShoplie;
    Unbinder unbinder;

    public static MessageFragmentFragment newInstance() {
        MessageFragmentFragment fragment = new MessageFragmentFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
        DaggerMessageFragmentComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .messageFragmentModule(new MessageFragmentModule(this))
                .build()
                .inject(this);
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_message, container, false);
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        //mPresenter.getmessage();
    }
    @Override
    public void setData(@Nullable Object data) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick(R.id.btn_sousuo)
    public void onViewClicked() {
        String s = editGuanjianzi.getText().toString().trim();
        mPresenter.getmessage(s);
    }

    @Override
    public void showDatafxian(NewsMessage newsMessage) {
        List<NewsMessage.DataBean> data = newsMessage.getData();
        //Toast.makeText(getActivity(), "data:" + data, Toast.LENGTH_SHORT).show();
        LinearLayoutManager manager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        receShoplie.setLayoutManager(manager);
        MyMessageAdapter myMessageAdapter = new MyMessageAdapter(getActivity(), data);
        receShoplie.setAdapter(myMessageAdapter);
    }
}
2.搜索布局

<LinearLayout 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:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        >

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="请输入关键字"
            android:id="@+id/edit_guanjianzi"
            />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:text="搜索"
            android:id="@+id/btn_sousuo"
            />

    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="9"
        android:id="@+id/rece_shoplie"
        />

</LinearLayout>

3.搜索适配器

public class MyMessageAdapter extends RecyclerView.Adapter<MyMessageAdapter.MessageViewHolder> {

    private Context context;
    private List<NewsMessage.DataBean> list;

    public MyMessageAdapter(Context context, List<NewsMessage.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MessageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.message_layout, null);
        MessageViewHolder messageViewHolder = new MessageViewHolder(inflate);
        return messageViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MessageViewHolder holder, int position) {

        holder.text_name.setText(list.get(position).getTitle());
        String[] splitImages = list.get(position).getImages().split("\\|");
        Uri parse = Uri.parse(splitImages[0]);
        holder.simp_ss.setImageURI(parse);
        holder.text_price.setText(list.get(position).getPrice()+"");
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MessageViewHolder extends RecyclerView.ViewHolder
    {

        private final SimpleDraweeView simp_ss;
        private final TextView text_price;
        private final TextView text_name;

        public MessageViewHolder(View itemView) {
            super(itemView);
            simp_ss = (SimpleDraweeView)itemView.findViewById(R.id.simp_ss);
            text_name = (TextView)itemView.findViewById(R.id.text_name);
            text_price = (TextView)itemView.findViewById(R.id.text_price);
        }
    }
}
4.搜索适配器布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_height="match_parent">

    <com.facebook.drawee.view.SimpleDraweeView
        android:layout_width="90dp"
        android:layout_height="90dp"
        app:placeholderImage="@mipmap/ic_launcher"
        android:id="@+id/simp_ss"
        android:layout_margin="@dimen/dp_10"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="name"
        android:textSize="20sp"
        android:layout_toRightOf="@id/simp_ss"
        android:id="@+id/text_name"
        android:layout_marginTop="@dimen/dp_10"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="price"
        android:textSize="20sp"
        android:layout_toRightOf="@id/simp_ss"
        android:id="@+id/text_price"
        android:textColor="#f00"
        android:layout_marginTop="70dp"
        />

</RelativeLayout>
5.搜索接口

//发现详情页面
    @GET("product/searchProducts?")
    Observable<NewsMessage> getMessage(@Query("keywords") String keywords);

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值