当我使用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;
}
}
添加回答
举报
0/150
提交
取消