亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我的 ArrayList 中的數據重復了數組最后輸入的數據。這是什么原因?

我的 ArrayList 中的數據重復了數組最后輸入的數據。這是什么原因?

森欄 2023-04-26 13:59:59
當我使用ArrayList自定義適配器在列表視圖中列出圖像時,代碼沒有顯示任何錯誤。問題是,在使用代碼時,只有我最后輸入的數據在列表視圖中顯示。為什么不能查看之前輸入的數據?我的活動課:public class SocialActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_social);        String json;        ImageView babu = (ImageView) findViewById(R.id.babu);        ListView lvsoc = (ListView) findViewById(R.id.list_social);        LinearLayout l1 = (LinearLayout) findViewById(R.id.layhead);        LayoutInflater inflater = null;        ArrayList<SubjectData> arrayList = new ArrayList<SubjectData>();        ArrayAdapter<SubjectData> a;        /*ArrayList<String> allcategory = new ArrayList<>();        ArrayList<String> allcategory1 = new ArrayList<>();        ArrayList<String> img = new ArrayList<>();        ArrayList<String> img1 = new ArrayList<>();*/        arrayList.add(new SubjectData("JAVA", "https://www.tutorialspoint.com/java/", "https://s18955.pcdn.co/wp-content/uploads/2017/11/Facebook-share-icon.png"));        arrayList.add(new SubjectData("Python", "https://www.tutorialspoint.com/python/", "https://www.tutorialspoint.com/python/images/python-mini.jpg"));        /*arrayList.add(new SubjectData("Javascript", "https://www.tutorialspoint.com/javascript/", "https://www.tutorialspoint.com/javascript/images/javascript-mini-logo.jpg"));        arrayList.add(new SubjectData("Cprogramming", "https://www.tutorialspoint.com/cprogramming/", "https://www.tutorialspoint.com/cprogramming/images/c-mini-logo.jpg"));        arrayList.add(new SubjectData("Cplusplus", "https://www.tutorialspoint.com/cplusplus/", "https://www.tutorialspoint.com/cplusplus/images/cpp-mini-logo.jpg"));
查看完整描述

1 回答

?
DIEA

TA貢獻1820條經驗 獲得超2個贊

您SubjectData擁有所有靜態字段。所以每個實例SubjectData都有相同的信息。


反而:


public class SubjectData {

    public String SubjectName;

    public String Link;

    public String Image;

    public SubjectData(String subjectName, String link, String image) {

        this.SubjectName = subjectName;

        this.Link = link;

        this.Image = image;

    }

}


查看完整回答
反對 回復 2023-04-26
  • 1 回答
  • 0 關注
  • 118 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號