第六次安卓作

第六次安卓作,第1张

概述packagecom.example.worksix;importandroidx.appcompat.app.AppCompatActivity;importandroid.os.Bundle;importandroid.view.View;importandroid.view.ViewGroup;importandroid.widget.AdapterView;importandroid.widget.BaseAdapter;importandroid.widget.ImageView
package com.example.worksix;import androIDx.appcompat.app.AppCompatActivity;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.AdapterVIEw;import androID.Widget.BaseAdapter;import androID.Widget.ImageVIEw;import androID.Widget.ListVIEw;import androID.Widget.TextVIEw;import androID.Widget.Toast;import org.w3c.dom.Text;public class MainActivity extends AppCompatActivity {    private ListVIEw ListVIEw;    private String arr[]={"京东商城","QQ","uc浏览器","微信","天猫","qq斗地主","微博"};    private int icons[] = new int[]{R.drawable.p1, R.drawable.p2, R.drawable.p3, R.drawable.p4, R.drawable.p5, R.drawable.p6, R.drawable.p7};    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        ListVIEw=findVIEwByID(R.ID.ListVIEw);        MyBaseAdapter myBaseAdapter=new MyBaseAdapter();        ListVIEw.setAdapter(myBaseAdapter);        ListVIEw.setonItemClickListener(new AdapterVIEw.OnItemClickListener() {            @OverrIDe            public voID onItemClick(AdapterVIEw<?> parent, VIEw vIEw, int position, long ID) {                Toast.makeText(MainActivity.this,"你点击的是第"+(position+1)+"个条目", Toast.LENGTH_SHORT).show();            }        });    }    protected class MyBaseAdapter extends BaseAdapter {        @OverrIDe        public int getCount() {            return arr.length;        }        @OverrIDe        public Object getItem(int position) {            return arr[position];        }        @OverrIDe        public long getItemID(int position) {            return position;        }        @OverrIDe        public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) {            VIEw vIEw=VIEw.inflate(MainActivity.this,R.layout.List_item,null);            ImageVIEw imageVIEw=vIEw.findVIEwByID(R.ID.iv);            TextVIEw textVIEw=vIEw.findVIEwByID(R.ID.Text);            imageVIEw.setBackgroundResource(icons[position]);            textVIEw.setText(arr[position]);            return vIEw;        }    }}
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="horizontal">    <linearLayout        androID:layout_margin="18dp"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content">        <ImageVIEw            androID:ID="@+ID/iv"            androID:layout_wIDth="62dp"            androID:layout_height="60dp" />        <TextVIEw            androID:ID="@+ID/Text"            androID:layout_wIDth="match_parent"            androID:layout_height="match_parent"            androID:gravity="center_vertical"            androID:textSize="35sp"            androID:layout_marginleft="10dp"/>    </linearLayout></linearLayout>
<?xml version="1.0" enCoding="utf-8"?><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:layout_height="match_parent"    tools:context=".MainActivity">    <ListVIEw        androID:ID="@+ID/ListVIEw"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"/></linearLayout>

总结

以上是内存溢出为你收集整理的第六次安卓作全部内容,希望文章能够帮你解决第六次安卓作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1098575.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存