搜索展示详情

依赖

compile 'com.google.code.gson:gson:2.8.2'
    compile 'com.squareup.okhttp3:okhttp:3.6.0'
    compile 'com.squareup.okio:okio:1.11.0'
    compile 'com.android.support:recyclerview-v7:25.3.1'
    compile 'com.jcodecraeer:xrecyclerview:1.3.2'
    testCompile 'junit:junit:4.12'
    compile 'com.xhb:xbanner:1.0.0'

Model

SearchModel

public class SearchModel {
    private IPresenterSearch iPresenterSearch;

    public SearchModel(IPresenterSearch iPresenterSearch) {
        this.iPresenterSearch = iPresenterSearch;
    }

    public void getData(String sname,String page, String searchUrl) {
/*        Map<String, String> map = new HashMap<>();
        map.put("keywords",sname);
        map.put("page","1");
        map.put("source","android");*/
        searchUrl = searchUrl+"?keywords="+sname+"&page="+page+"&source=android";
        Log.d("url",searchUrl);
        OkHttp3Util.doGet(searchUrl, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if(response.isSuccessful()){
                    String json = response.body().string();
                    if(json!=null){
                        Gson gson = new Gson();
                        SearchBean searchBean = gson.fromJson(json, SearchBean.class);
                        iPresenterSearch.onSuccess(searchBean);
                    }
                }
            }
        });
    }
}

XiangQing

public class XiangQingModel {
    private IPresenterXiangQing iPresenterXiangQing;

    public XiangQingModel(IPresenterXiangQing iPresenterXiangQing) {
        this.iPresenterXiangQing = iPresenterXiangQing;
    }

    public void getData(int pid, String searchUrl) {
        //searchUrl = searchUrl+"?pid="+pid+"&source=android";

        OkHttp3Util.doGet(searchUrl+"?pid="+pid, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                if(response.isSuccessful()){

                    String json = response.body().string();
                    if(json!=null){
                        Gson gson = new Gson();
                        XiangQingBean xiangQingBean = gson.fromJson(json, XiangQingBean.class);
                        iPresenterXiangQing.onSuccess(xiangQingBean);
                    }
                }
            }
        });
    }
}

Presenter

SerachPresenter

public class SearchPresenter implements IPresenterSearch{
    private IViewSearch iViewSearch;
    private final SearchModel searchModel;

    public SearchPresenter(IViewSearch iViewSearch) {
        this.iViewSearch = iViewSearch;
        searchModel = new SearchModel(this);
    }

    public void getData(String sname,String page, String searchUrl) {
        searchModel.getData(sname, page,searchUrl);
    }

    @Override
    public void onSuccess(SearchBean searchBean) {
        iViewSearch.onSuccess(searchBean);
    }
}

IPresenterSerach

public interface IPresenterSearch {
    void onSuccess(SearchBean searchBean);
}

XiangQingPresenter

public class XiangQingPresenter implements IPresenterXiangQing{
    private IViewXiangQing iViewXiangQing;
    private final XiangQingModel xiangQingModel;

    public XiangQingPresenter(IViewXiangQing iViewXiangQing) {
        this.iViewXiangQing = iViewXiangQing;
        xiangQingModel = new XiangQingModel(this);
    }

    public void getData(int pid, String searchUrl) {
        xiangQingModel.getData(pid,searchUrl);
    }

    @Override
    public void onSuccess(XiangQingBean xiangQingBean) {
        iViewXiangQing.onSuccess(xiangQingBean);
    }
}

IPresenterXiangQing

public interface IPresenterXiangQing {
    void onSuccess(XiangQingBean xiangQingBean);
}

View

IViewSearch

public interface IViewSearch {
    void onSuccess(SearchBean searchBean);
}

IViewXiangQing

public interface IViewXiangQing {
    void onSuccess(XiangQingBean xiangQingBean);
}

RecyclerView点击事件

public interface OnItemClickListener {
    void onItemClick(View view , int position);
}

Activity

搜索

public class MainActivity extends AppCompatActivity{
    private MyViewLiuShi mFlowLayout;
    private String mNames[] = {
            "welcome","android","TextView",
            "apple","jamy","kobe bryant",
            "jordan","layout","viewgroup",
            "margin","padding","text"
    };
    private TextView ed_text;
    private ListView lv;
    private LinearLayout search_clear;
    private LinearLayout search_history;
    private List<String> list;
    private ArrayAdapter adapter;
    private Dao dao;
    private Button search;
    private String sname;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        search = (Button) findViewById(R.id.search);
        search_history = (LinearLayout) findViewById(R.id.search_history);
        search_clear = (LinearLayout) findViewById(R.id.search_clear);
        ed_text = (TextView) findViewById(R.id.ed_text);
        lv = (ListView) findViewById(R.id.lv);
        initChildViews();//流式布局
        dao = new Dao(MainActivity.this);
        //查询历史搜索
        dao = new Dao(this);
        list = dao.select();
        adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, list);
        lv.setAdapter(adapter);
        //集合的长度决定历史搜索是否显示
        ishide();

    }

    private void initChildViews() {
        // TODO Auto-generated method stub
        mFlowLayout = (MyViewLiuShi) findViewById(R.id.flowlayout);
        ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.leftMargin = 5;
        lp.rightMargin = 5;
        lp.topMargin = 5;
        lp.bottomMargin = 5;
        for(int i = 0; i < mNames.length; i ++){
            TextView view = new TextView(this);
            view.setText(mNames[i]);
            view.setTextColor(Color.BLACK);
            view.setTextSize(15);
            view.setBackgroundDrawable(getResources().getDrawable(R.drawable.liushi_shape));
            mFlowLayout.addView(view,lp);
        }
    }
    //清除历史
    public void clear(View view) {
        dao.del();
        list = dao.select();
        adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, list);
        lv.setAdapter(adapter);
        //集合的长度决定历史搜索是否显示
        ishide();
    }
    //搜索
    public void search(View view) {
        sname = ed_text.getText().toString();
        Intent intent = new Intent(MainActivity.this,ShowActivity.class);
        intent.putExtra("sname",sname);
        startActivity(intent);
        if(sname!=null){
            dao.add(sname);//添加
        }
        /*//查询
        list = dao.select();
        if(list.size() == 1){
            dao.add("清空历史搜索");
        }*/
        //查询
        list = dao.select();
        //设置适配器
        adapter = new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1, list);
        lv.setAdapter(adapter);
        //条目点击事件
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if(i == list.size()-1){
                    dao.del();
                    list = dao.select();
                    adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, list);
                    lv.setAdapter(adapter);
                    //集合的长度决定历史搜索是否显示
                    ishide();
                }
            }
        });
        //集合的长度决定历史搜索是否显示
        ishide();

    }
    private void ishide() {
        if(list.size() > 0){
            search_history.setVisibility(View.VISIBLE);
            search_clear.setVisibility(View.VISIBLE);
        }else{
            search_history.setVisibility(View.GONE);
            search_clear.setVisibility(View.GONE);
        }
    }
}

展示

public class ShowActivity extends AppCompatActivity implements IViewSearch {
    private XRecyclerView xrv;
    private CheckBox ck;
    boolean flag = false;//定义全局变量用来保存按钮的状态
    private TextView fan;
    private SearchPresenter searchPresenter;
    private List<SearchBean.DataBean> data = new ArrayList<>();
    private String encodecontent;
    private int num = 1;
    private SearchRecyclerAdapter adapter;
    private SearchRecyclerGVAdapter gvAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show);
        fan = (TextView) findViewById(R.id.fan);
        xrv = (XRecyclerView) findViewById(R.id.xrv);
        ck = (CheckBox) findViewById(R.id.ck);

        try {
            //接收搜索页面传来的数据
            Intent intent = getIntent();
            String sname = intent.getStringExtra("sname");
            encodecontent = URLEncoder.encode(sname, "utf-8");
            searchPresenter = new SearchPresenter(this);
            searchPresenter.getData(encodecontent,"1", ApiUtil.SEARCH_URL);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }



    }
    private void setAdapter(List<SearchBean.DataBean> data) {
        //设置适配器
        adapter = new SearchRecyclerAdapter(ShowActivity.this,data);
        xrv.setAdapter(adapter);
        //设置管理器
        xrv.setLayoutManager(new LinearLayoutManager(ShowActivity.this, LinearLayout.VERTICAL,false));
    }
    @Override
    public void onSuccess(final SearchBean searchBean) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(ShowActivity.this,searchBean.getMsg(), Toast.LENGTH_SHORT).show();
                data.addAll(searchBean.getData());
                //设置默认数据
                setAdapter(data);//设置管理器、适配器
                ck.setChecked(flag);//设置按钮默认值
                //点击事件
                ck.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if(flag){
                            setAdapter(data);//设置管理器、适配器
                            ck.setChecked(false);
                            flag = ck.isChecked();
                        }else{
                            //设置适配器
                            gvAdapter = new SearchRecyclerGVAdapter(ShowActivity.this, data);
                            xrv.setAdapter(gvAdapter);
                            //设置管理器--瀑布
                            xrv.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
                            ck.setChecked(true);
                            flag = ck.isChecked();
                        }
                        gvAdapter.setMyItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(View view, int position) {
                                Intent intent = new Intent(ShowActivity.this,XiangQingActivity.class);
                                intent.putExtra("pid",data.get(position).getPid());
                                startActivity(intent);
                            }
                        });
                    }
                });
                //返回
                fan.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                    }
                });
                //设置XRecyclerView的上下拉监听方法
                xrv.setLoadingListener(new XRecyclerView.LoadingListener() {
                    @Override
                    public void onRefresh() {
                        data.clear();
                        searchPresenter.getData(encodecontent,"1",ApiUtil.SEARCH_URL);
                        xrv.refreshComplete();//刷新完成
                    }

                    @Override
                    public void onLoadMore() {
                        num++;
                        searchPresenter.getData(encodecontent,num+"",ApiUtil.SEARCH_URL);
                        xrv.loadMoreComplete();//加载完成
                    }
                });
                //点击事件
                adapter.setMyItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
                        //Toast.makeText(ShowActivity.this, data.get(position).getTitle(), Toast.LENGTH_SHORT).show();
                        Intent intent = new Intent(ShowActivity.this,XiangQingActivity.class);
                        intent.putExtra("pid",data.get(position).getPid());
                        startActivity(intent);
                    }
                });

            }
        });
    }
}

详情

public class XiangQingActivity extends AppCompatActivity implements IViewXiangQing{

    private XBanner banner_1;
    private XiangQingPresenter xiangQingPresenter;
    List<String> imglist = new ArrayList<>();
    private TextView xq_title;
    private TextView xq_yuanprice;
    private TextView xq_price;
    private int pid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xiang_qing);
        TextView fan = (TextView) findViewById(R.id.fan);
        banner_1 = (XBanner) findViewById(R.id.banner_1);
        xq_title = (TextView) findViewById(R.id.xq_title);
        xq_price = (TextView) findViewById(R.id.xq_price);
        xq_yuanprice = (TextView) findViewById(R.id.xq_yuanprice);
        xiangQingPresenter = new XiangQingPresenter(this);
        //返回
        fan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        //得到自条目的索引值
        pid = getIntent().getIntExtra("pid", 0);
        xiangQingPresenter.getData(pid, ApiUtil.XIANGQING_URL);
    }

    @Override
    public void onSuccess(final XiangQingBean xiangQingBean) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if(xiangQingBean!=null){
                    XiangQingBean.DataBean data = xiangQingBean.getData();
                    String images = data.getImages();
                    String[] split = images.split("\\|");
                    for(String imgurl:split){
                        imglist.add(imgurl);
                    }
                    //设置图片
                    banner_1.setData(imglist);
                    banner_1.setPointsIsVisible(false);
                    banner_1.setmAutoPlayAble(false);
                    banner_1.setmAdapter(new XBanner.XBannerAdapter() {
                        @Override
                        public void loadBanner(XBanner banner, View view, int position) {
                            Glide.with(XiangQingActivity.this).load(imglist.get(position)).into((ImageView) view);
                        }
                    });
                    //设置数据
                    xq_title.setText(data.getTitle());
                    xq_price.setText("优惠价:"+data.getPrice());
                    xq_yuanprice.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
                    xq_yuanprice.setText("原价:"+data.getBargainPrice());
                }

            }
        });
    }
    //添加购物车
    public void addCar(View view) {
        OkHttp3Util.doGet(ApiUtil.ADD_CART + "?pid=" + pid + "&uid=2753", new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                 if(response.isSuccessful()){
                     final String json = response.body().string();
                     runOnUiThread(new Runnable() {
                         @Override
                         public void run() {
                             if(json!=null){
                                 try {
                                     JSONObject obj = new JSONObject(json);
                                     String code = obj.getString("code");
                                     if("0".equals(code)){
                                         Toast.makeText(XiangQingActivity.this,obj.getString("msg"),Toast.LENGTH_SHORT).show();
                                     }else{
                                         Toast.makeText(XiangQingActivity.this,obj.getString("msg"),Toast.LENGTH_SHORT).show();
                                     }

                                 } catch (JSONException e) {
                                     e.printStackTrace();
                                 }

                             }
                         }
                     });

                 }
            }
        });
    }
}

APIUtil

public class ApiUtil {
    public static final String ADD_CART = "https://www.zhaoapi.cn/product/addCart";

    public static final String XIANGQING_URL = "https://www.zhaoapi.cn/product/getProductDetail";

    public static final String SEARCH_URL = "http://120.27.23.105/product/searchProducts";
}

数据库

public class MyDBHelper extends SQLiteOpenHelper {
    public MyDBHelper(Context context) {
        super(context, "search_database", null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("create table search_tb(id Integer primary key,content varchar(50))");
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}

Dao层

public class Dao {
    MyDBHelper helper;
    Context context;
    private SQLiteDatabase sqLiteDatabase;

    public Dao(Context context) {
        this.helper = new MyDBHelper(context);
    }
    public void add(String content){
        sqLiteDatabase = helper.getWritableDatabase();
        sqLiteDatabase.execSQL("insert into search_tb (content) values (?)",new Object[]{content});
        sqLiteDatabase.close();
    }

    public List<String> select(){
        List<String> list = new ArrayList<>();
        sqLiteDatabase = helper.getReadableDatabase();
        Cursor cursor = sqLiteDatabase.rawQuery("select *from search_tb", null);
        while(cursor.moveToNext()){
            String string = cursor.getString(1);
            list.add(string);
        }

        return list;
    }
    public void del(){
        sqLiteDatabase = helper.getWritableDatabase();
        sqLiteDatabase.execSQL("delete from search_tb");
        sqLiteDatabase.close();
    }
}

切换布局适配器

list

public class SearchRecyclerAdapter extends XRecyclerView.Adapter<SearchRecyclerHolder> implements View.OnClickListener{
    Context context;
    List<SearchBean.DataBean> data;
    private OnItemClickListener monItemClickListener;
    //暴露给外面的调用者,定义一个设置Listener的方法():
    public void setMyItemClickListener(OnItemClickListener monItemClickListener){
        this.monItemClickListener = monItemClickListener;
    }

    public SearchRecyclerAdapter(Context context, List<SearchBean.DataBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public SearchRecyclerHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
        SearchRecyclerHolder searchRecyclerHolder = new SearchRecyclerHolder(view);
        view.setOnClickListener(this);
        return searchRecyclerHolder;
    }

    @Override
    public void onBindViewHolder(SearchRecyclerHolder holder, int position) {
        SearchBean.DataBean dataBean = data.get(position);
        String images = dataBean.getImages();
        String[] split = images.split("\\|");
        //设置数据
        Glide.with(context).load(split[0]).into(holder.img);
        holder.price.setText(dataBean.getPrice()+"");
        holder.title.setText(dataBean.getTitle());
        holder.itemView.setTag(position);
    }

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

    @Override
    public void onClick(View view) {
        if(monItemClickListener != null){
            monItemClickListener.onItemClick(view, (Integer) view.getTag());
        }
    }
}

Grid

public class SearchRecyclerGVAdapter extends RecyclerView.Adapter<SearchRecyclerHolder> implements View.OnClickListener{
    Context context;
    List<SearchBean.DataBean> data;
    private OnItemClickListener monItemClickListener;

    public void setMyItemClickListener(OnItemClickListener onItemClickListener){
        this.monItemClickListener = monItemClickListener;
    }
    public SearchRecyclerGVAdapter(Context context, List<SearchBean.DataBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public SearchRecyclerHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.grid_item, parent, false);
        SearchRecyclerHolder searchRecyclerHolder = new SearchRecyclerHolder(view);
        return searchRecyclerHolder;
    }

    @Override
    public void onBindViewHolder(SearchRecyclerHolder holder, int position) {
        SearchBean.DataBean dataBean = data.get(position);
        String images = dataBean.getImages();
        String[] split = images.split("\\|");
        //设置数据
        Glide.with(context).load(split[0]).into(holder.img);
        holder.price.setText(dataBean.getPrice()+"");
        holder.title.setText(dataBean.getTitle());
        holder.itemView.setTag(position);
    }

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

    @Override
    public void onClick(View view) {
        if(monItemClickListener != null){
            monItemClickListener.onItemClick(view, (Integer) view.getTag());
        }
    }
}

Holder

public class SearchRecyclerHolder extends XRecyclerView.ViewHolder {
    public ImageView img;
    public TextView title;
    public TextView price;

    public SearchRecyclerHolder(View itemView) {
        super(itemView);
        img = (ImageView) itemView.findViewById(R.id.img);
        price = (TextView) itemView.findViewById(R.id.price);
        title = (TextView) itemView.findViewById(R.id.title);
    }
}

布局

展示

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:padding="10dp">
        <TextView
            android:textSize="35dp"
            android:id="@+id/fan"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="<"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="搜索商品"
            android:textSize="35dp"
            android:layout_centerInParent="true"/>
        <CheckBox
            android:button="@null"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:id="@+id/ck"
            android:background="@drawable/myselect"
            android:layout_alignParentRight="true" />
    </RelativeLayout>
    <TextView
        android:background="#f1ebeb"
        android:layout_width="match_parent"
        android:layout_height="3dp"/>
    <XRecyclerView
        android:id="@+id/xrv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"></XRecyclerView>

自定义转换布局

<item android:state_checked="false" android:drawable="@drawable/kind_grid"></item>
    <item android:state_checked="true" android:drawable="@drawable/kind_liner"></item>
    <item android:drawable="@drawable/kind_liner"></item>

详情布局

<LinearLayout
        android:id="@+id/linear1"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp">
        <TextView
            android:textSize="35dp"
            android:id="@+id/fan"
            android:text="<"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textSize="30dp"
            android:text="商品详情"/>
    </LinearLayout>
    <TextView
        android:layout_below="@id/linear1"
        android:id="@+id/linear2"
        android:background="#f1ebeb"
        android:layout_width="match_parent"
        android:layout_height="3dp" />
    <com.stx.xhb.xbanner.XBanner
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_below="@id/linear2"
        android:id="@+id/banner_1"
        android:layout_width="match_parent"
        android:layout_height="220dp"></com.stx.xhb.xbanner.XBanner>
    <LinearLayout
        android:layout_below="@id/banner_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="10dp">
        <TextView
            android:id="@+id/xq_title"
            android:layout_marginBottom="8dp"
            android:textSize="20dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/xq_yuanprice"
            android:textSize="20dp"
            android:layout_marginBottom="8dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/xq_price"
            android:textColor="#f00"
            android:textSize="20dp"
            android:layout_marginBottom="8dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

    <LinearLayout
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#000"/>
        <Button
            android:background="#fff"
            android:onClick="addCar"
            android:text="加入购物车"
            android:textSize="25dp"
            android:layout_marginBottom="0dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>

GridView布局

 <ImageView
            android:id="@+id/img"
            android:layout_width="180dp"
            android:layout_height="180dp"
            android:src="@mipmap/ic_launcher"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <TextView
                android:id="@+id/title"
                android:text="bbbbbbbbb"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
            <TextView
                android:id="@+id/price"
                android:text="aaaaa"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />
        </LinearLayout>

ListView布局

<ImageView
            android:id="@+id/img"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:src="@mipmap/ic_launcher"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <TextView
                android:id="@+id/title"
                android:text="bbbbbbbbb"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
            <TextView
                android:id="@+id/price"
                android:text="aaaaa"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1" />
        </LinearLayout>























  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
通用接口实现类LinkJOS 扩展于:public class LinkJOS extends LinkOAuth2(LinkOAuth2 extends JspEasy) 构造函数 LinkJOS(HttpServletRequest request,HttpServletResponse response) 京东JOS接口访问函数 public String link2(String link,String method,Bag sys,Bag apps,String appSecret,String file,String FileField) 作用:访问京东JOS平台的所有接口 参数: String link,京东JOS平台接口访问地址,目前固定为:https://api.jd.com/routerjson String method,向京东JOS平台提交数据时的方法,需要应用级别参数时建议用POST方法,不需要时用GET(参见后边的实例) Bag sys,系统级别参数书包(一般只需在接口参数文件中放入接口方法即可,参见后边的实例) Bag apps,应用级别参数书包(在接口参数文件中放入必须的应用级别参数,若不需要应用级别参数时直接用new Bag(-1)构造一个空书包即可,参见后边的实例) String appSecret,应用证书中的App Secret,前边已经设置,固定用"@{pPage:app_secret}"即可 String file,调用上传文件接口上传文件(如图片)到京东JOS平台时的文件全名(含相对路径,如:images/logo.png),不是调用上传文件接口时为空字符串即可(参见后边的实例) String FileField,调用上传文件接口上传文件(如图片)到京东JOS平台时的字段名,配合前边的参数,不是调用上传文件接口时为空字符串即可(参见后边的实例) 返回为京东JOS平台接口对应的JSON格式的字符串 JSON文本解析方法 public void parseJson(String json) 作用:解析京东JOS平台接口返回的JSON格式的字符串,并根据内容生成N个对应的书包 参数:String json,京东JOS平台接口返回的JSON格式的字符串 根据JSON文本的内容在系统中生成N个书包,根书包名称为j0,下一层的josn文本内容生成的书包名称用上一层的Key放在上一层的书名中,下边用实例说明寻找对应书包的方法: 如店铺信息查询接口jingdong.vender.shop.query返回的json文本为 { "jingdong_vender_shop_query_responce": { "shop_jos_result": { "open_time": "", "shop_id": "", "category_main_name": "", "category_main": "", "vender_id": "", "brief": "", "logo_url": "", "shop_name": "" } } } 找出店铺信息书包名的方法如下 @{j0:jingdong_vender_shop_query_responce} @{@{pPage:bag}:shop_jos_result} 这时候的@{pPage:bag}即为需要的店铺信息书包名 具体用法请阅读下载包中的《京东卖家如何快速开发网店工具软件》

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值