zoukankan      html  css  js  c++  java
  • js标题

    public class MainActivity extends AppCompatActivity {
    private ListView lv;
    private RequestQueue requestQueue;
    private MyAdapter ad;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    lv= (ListView) findViewById(R.id.listview);
    getVolly();
    }

    public void getVolly() {
    requestQueue= Volley.newRequestQueue(this);
    StringRequest s=new StringRequest(Request.Method.GET, "http://www.qubaobei.com/ios/cf/dish_list.php?stage_id=1&limit=20&page=1", new Response.Listener<String>() {
    @Override
    public void onResponse(String s) {
    FoodBean fb= JSONObject.parseObject(s,FoodBean.class);
    ad=new MyAdapter(getApplicationContext(),fb);
    lv.setAdapter(ad);
    }
    }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError volleyError) {
    }
    });
    requestQueue.add(s);
    }
    }

    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    public class MyAdapter extends BaseAdapter {
    private FoodBean foodBean;
    private Context context;
    public MyAdapter(Context context,FoodBean foodBean){
    this.foodBean=foodBean;
    this.context=context;

    }
    @Override
    public int getCount() {
    if (foodBean.getData()!=null){
    return foodBean.getData().size();
    }
    return 0;
    }

    @Override
    public Object getItem(int position) {
    if (foodBean.getData()!=null){
    return foodBean.getData().get(position);
    }
    return null;
    }

    @Override
    public long getItemId(int position) {
    return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder vh=null;
    if (convertView==null){
    vh=new ViewHolder();
    convertView= LayoutInflater.from(context).inflate(R.layout.list_item,null);
    vh.iv= (ImageView) convertView.findViewById(R.id.imageView);
    vh.tv= (TextView) convertView.findViewById(R.id.textView);
    vh.tv1= (TextView) convertView.findViewById(R.id.textView2);
    convertView.setTag(vh);
    }else{
    vh= (ViewHolder) convertView.getTag();
    }
    vh.tv.setText(foodBean.getData().get(position).getTitle());
    vh.tv1.setText("数量:"+foodBean.getData().get(position).getCollect_num());
    Glide.with(context).load(foodBean.getData().get(position).getPic()).into(vh.iv);
    return convertView;
    }
    class ViewHolder{
    ImageView iv;
    TextView tv;
    TextView tv1;

    }
    }

    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    <ListView
    android:id="@+id/listview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

    <ImageView
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:src="@mipmap/ic_launcher"
    android:layout_marginLeft="28dp"
    android:layout_marginStart="28dp"
    android:id="@+id/imageView"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="17dp" />

    <TextView
    android:text="TextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="29dp"
    android:layout_marginStart="29dp"
    android:id="@+id/textView"
    android:layout_alignTop="@+id/imageView"
    android:layout_toRightOf="@+id/imageView"
    android:layout_toEndOf="@+id/imageView"
    android:layout_marginTop="19dp" />

    <TextView
    android:text="TextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView2"
    android:layout_marginRight="24dp"
    android:layout_marginEnd="24dp"
    android:layout_alignBaseline="@+id/textView"
    android:layout_alignBottom="@+id/textView"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

  • 相关阅读:
    关于 php json float 出现很多位的问题
    做 Excel 的 XML schema.xsd
    笔记:Python 默认参数必须指向不变对象
    Bartender 使用 Excel xlsx 数据库时出现 0x800A0E7A
    Javascript 中 的 for ... in 和 for ... of 差别
    关于跨域资料收集 (2019-01-11)
    ThinkPHP3 和 ThinkPHP5 不是一个团队做的
    记录一下:给电推剪改锂电池
    为你的Web程序加个启动画面
    前端不为人知的一面--前端冷知识集锦 前端已经被玩儿坏了!像console.log()可以向控制台输出图片
  • 原文地址:https://www.cnblogs.com/yudada/p/wwdasdsakp.html
Copyright © 2011-2022 走看看