直播app開發,Android ListView好友列表展示

zhibo系統開發發表於2022-05-30

直播app開發,Android ListView好友列表展示

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


html

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


Java程式碼

java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity {
    private ArrayList datas;
    private ListView listview;
    private int[] iconArray =
            {R.mipmap.hope, R.mipmap.meili, R.mipmap.brightness,
                    R.mipmap.banye, R.mipmap.bianfeng, R.mipmap.feitian,R.mipmap.guilaixi};
    private String[] starArray = {"hope", "美麗心情", "brightness", "半葉", "彼岸風", "飛天", "歸來兮"};
    private String str="這個傢伙很懶";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listview = findViewById(R.id.listview);
        datas = new ArrayList();
        for (int i = 0; i < starArray.length; i++) {
            HashMap listData = new HashMap();
            listData.put("image", iconArray[i]);
            listData.put("name", starArray[i]);
            listData.put("neirong",str);
            datas.add(listData);
        }
        //建立介面卡物件
        SimpleAdapter starAdapter = new SimpleAdapter(this, datas,
                R.layout.item_list, new String[]{"image", "name","neirong"},
                new int[]{R.id.iv_icon, R.id.tv_name,R.id.neirong});
        //設定介面卡
        listview.setAdapter(starAdapter);
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view,
                                    int position, long l) {
                Toast.makeText(MainActivity.this,
                        "好友" + starArray[position], Toast.LENGTH_LONG).show();
            }
        });
    }
}


以上就是直播app開發,Android ListView好友列表展示, 更多內容歡迎關注之後的文章


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69978258/viewspace-2897912/,如需轉載,請註明出處,否則將追究法律責任。

相關文章