直播app开发,Android ListView好友列表展示

直播app开发,Android ListView好友列表展示

 

1
<?xml version="1.0" encoding="utf-8"?><br><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br>    xmlns:tools="http://schemas.android.com/tools"<br>    android:layout_width="match_parent"<br>    android:layout_height="match_parent"<br>    android:orientation="vertical"<br>    tools:ignore="ExtraText"><br>    <TextView<br>        android:layout_width="match_parent"<br>        android:layout_height="wrap_content"<br>        android:text="好友列表"<br>        android:textSize="20dp" /><br>    <LinearLayout<br>        android:layout_width="match_parent"<br>        android:layout_height="match_parent"><br>        <ListView<br>            android:id="@+id/listview"<br>            android:layout_width="match_parent"<br>            android:layout_height="wrap_content"<br>            android:layout_alignParentRight="true"<br>            android:layout_centerVertical="true"<br>            android:spinnerMode="dialog" /><br>    </LinearLayout><br></LinearLayout><br>《item list》文件

html

 

1
<?xml version="1.0" encoding="utf-8"?><br><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br>    android:layout_width="match_parent"<br>    android:layout_height="wrap_content"<br>    android:orientation="horizontal"><br>    <LinearLayout<br>        android:layout_width="0dp"<br>        android:layout_height="match_parent"<br>        android:layout_weight="1"><br>        <ImageView<br>            android:id="@+id/iv_icon"<br>            android:layout_width="80dp"<br>            android:layout_height="80dp"<br>            android:gravity="center" /><br>    </LinearLayout><br>    <LinearLayout<br>        android:layout_width="0dp"<br>        android:layout_height="match_parent"<br>        android:layout_weight="3"<br>        android:orientation="vertical"><br>        <TextView<br>            android:id="@+id/tv_name"<br>            android:textStyle="bold"<br>            android:layout_width="match_parent"<br>            android:layout_height="0dp"<br>            android:layout_weight="1"<br>            android:textColor="#000000"<br>            android:textSize="30dp" /><br>        <TextView<br>            android:id="@+id/neirong"<br>            android:textColor="#969696"<br>            android:layout_width="match_parent"<br>            android:layout_weight="1"<br>            android:layout_height="0dp"<br>            android:textSize="17sp"/><br>    </LinearLayout><br></LinearLayout>

 

Java代码

 

1
java<br>import androidx.appcompat.app.AppCompatActivity;<br>import android.os.Bundle;<br>import android.view.View;<br>import android.widget.AdapterView;<br>import android.widget.ListView;<br>import android.widget.SimpleAdapter;<br>import android.widget.Toast;<br>import java.util.ArrayList;<br>import java.util.HashMap;<br>public class MainActivity extends AppCompatActivity {<br>    private ArrayList datas;<br>    private ListView listview;<br>    private int[] iconArray =<br>            {R.mipmap.hope, R.mipmap.meili, R.mipmap.brightness,<br>                    R.mipmap.banye, R.mipmap.bianfeng, R.mipmap.feitian,R.mipmap.guilaixi};<br>    private String[] starArray = {"hope", "美丽心情", "brightness", "半叶", "彼岸风", "飞天", "归来兮"};<br>    private String str="这个家伙很懒";<br>    @Override<br>    protected void onCreate(Bundle savedInstanceState) {<br>        super.onCreate(savedInstanceState);<br>        setContentView(R.layout.activity_main);<br>        listview = findViewById(R.id.listview);<br>        datas = new ArrayList();<br>        for (int i = 0; i < starArray.length; i++) {<br>            HashMap listData = new HashMap();<br>            listData.put("image", iconArray[i]);<br>            listData.put("name", starArray[i]);<br>            listData.put("neirong",str);<br>            datas.add(listData);<br>        }<br>        //创建适配器对象<br>        SimpleAdapter starAdapter = new SimpleAdapter(this, datas,<br>                R.layout.item_list, new String[]{"image", "name","neirong"},<br>                new int[]{R.id.iv_icon, R.id.tv_name,R.id.neirong});<br>        //设置适配器<br>        listview.setAdapter(starAdapter);<br>        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {<br>            @Override<br>            public void onItemClick(AdapterView<?> adapterView, View view,<br>                                    int position, long l) {<br>                Toast.makeText(MainActivity.this,<br>                        "好友" + starArray[position], Toast.LENGTH_LONG).show();<br>            }<br>        });<br>    }<br>}

 

以上就是直播app开发,Android ListView好友列表展示, 更多内容欢迎关注之后的文章

 

posted @   云豹科技-苏凌霄  阅读(36)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示