zoukankan      html  css  js  c++  java
  • 安卓9.30

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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:layout_height="match_parent"
        tools:context=".MainActivity">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ListView
                android:id="@+id/lv1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            </ListView>
        </LinearLayout>
    </RelativeLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ImageView
            android:id="@+id/iv"
            android:layout_width="170dp"
            android:layout_height="150dp"
            >
    
        </ImageView>
    
    
        <TextView
            android:id="@+id/tv1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="50dp"
            android:text="111">
    
        </TextView>
    
    
    </LinearLayout>
    package com.example.myapplication;
    
    public class Fruit {
        private String name;  
        private int imageId;  
      
        public Fruit(String name, int imageId) {  
            this.name = name;  
            this.imageId = imageId;  
        }  
      
        public String getName() {  
            return name;  
        }  
      
        public int getImageId() {  
            return imageId;  
        }  
    
    }
    package com.example.myapplication;
    
    import java.util.List;
    
    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.ArrayAdapter;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    public class FruitAdapter extends ArrayAdapter {
         private final int resourceId;  
          
            public FruitAdapter(Context context, int textViewResourceId, List<Fruit> objects) {  
                super(context, textViewResourceId, objects);  
                resourceId = textViewResourceId;  
            }  
            @Override  
            public View getView(int position, View convertView, ViewGroup parent) {  
                Fruit fruit = (Fruit) getItem(position); // ��ȡ��ǰ���Fruitʵ��  
                View view = LayoutInflater.from(getContext()).inflate(resourceId, null);//ʵ����һ������
                ImageView fruitImage = (ImageView) view.findViewById(R.id.iv);//��ȡ�ò����ڵ�ͼƬ��ͼ
                TextView fruitName = (TextView) view.findViewById(R.id.tv1);//��ȡ�ò����ڵ��ı���ͼ
                fruitImage.setImageResource(fruit.getImageId());//ΪͼƬ��ͼ����ͼƬ��Դ
                fruitName.setText(fruit.getName());//Ϊ�ı���ͼ�����ı�����
                return view;
            }  
        
    
    }
    package com.example.myapplication;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.widget.ListView;
    
    public class MainActivity extends Activity {
        private List<Fruit> fruitList = new ArrayList<Fruit>(); 
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            initFruits(); // ��ʼ��ˮ������
            FruitAdapter adapter = new FruitAdapter(MainActivity.this, R.layout.fruit_item, fruitList);  
            ListView listView = (ListView) findViewById(R.id.lv1);
            listView.setAdapter(adapter);  
        }
    
    
        private void initFruits(){
             Fruit apple = new Fruit("Apple", R.drawable.tu);
             fruitList.add(apple);
             Fruit banana = new Fruit("Banana",  R.drawable.tu);
             fruitList.add(banana);
             Fruit orange = new Fruit("Orange",R.drawable.tu);
             fruitList.add(orange);
             Fruit watermelon = new Fruit("Watermelon", R.drawable.tu);
             fruitList.add(watermelon);
             Fruit pear = new Fruit("Pear", R.drawable.tu);
             fruitList.add(pear);
             Fruit grape = new Fruit("Grape", R.drawable.tu);
             fruitList.add(grape);
             Fruit pineapple = new Fruit("Pineapple", R.drawable.tu);
             fruitList.add(pineapple);
             Fruit strawberry = new Fruit("Strawberry", R.drawable.tu);
             fruitList.add(strawberry);
             Fruit cherry = new Fruit("Cherry", R.drawable.tu);
             fruitList.add(cherry);
             Fruit mango = new Fruit("Mango", R.drawable.tu);
             fruitList.add(mango);
    
        
        }
    
    
       
        
    }

  • 相关阅读:
    elasticsearch 启动
    经纬度解析API
    http://t.cn/xxxxx的短链接如何生成?
    IIS+PHP上传文件大小限制和上传时间限制,iis7和iis8上传文件大小限制和上传时间限制
    WIN2003+IIS6环境SSL证书的安装
    如何创建文件名前带点的文件夹,文件夹名字带点
    解决MYSQL的错误:Got a packet bigger than 'max_allowed_packet' bytes
    php 设置临时内存和超时设置脚本最大执行时间
    谷歌地图 API 开发之获取坐标以及街道详情
    隐藏 google 地图 Logo 隐藏 百度 地图 Logo
  • 原文地址:https://www.cnblogs.com/M1223631418/p/13764123.html
Copyright © 2011-2022 走看看