繁体   English   中英

如何将数据添加到列表并在下一页上使用其数据并在listview中显示

[英]How to add data to list and use its data on next page and show in listview

我有2个一级是login_class第二个是student_class,它显示了学生的详细信息。

我要做的就是当我登录时。 作为回应,我得到学生的详细信息,如student_name,student_srno,student_father_name,student_mother_name等。

这是我的bean(Getter Setter)类

    package com.smartschoolapp;

public class Bean {

String username, password, srno, studentname, classname, sec, contact,
father_name, mother_name, dob;



public  Bean(String username,String password,String srno,String studentname,String classname,String sec,String contact,String father_name,String mother_name,String dob) {
    this.username=username;
    this.password= password;
    this.srno=srno;
    this.studentname=studentname;
    this.classname=classname;
    this.sec=sec;
    this.contact=contact;
    this.father_name=father_name;
    this.mother_name=mother_name;
    this.dob =dob;
}

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public String getSrno() {
    return srno;
}

public void setSrno(String srno) {
    this.srno = srno;
}

public String getStudentname() {
    return studentname;
}

public void setStudentname(String studentname) {
    this.studentname = studentname;
}

public String getClassname() {
    return classname;
}

public void setClassname(String classname) {
    this.classname = classname;
}

public String getSec() {
    return sec;
}

public void setSec(String sec) {
    this.sec = sec;
}

public String getContact() {
    return contact;
}

public void setContact(String contact) {
    this.contact = contact;
}

public String getFather_name() {
    return father_name;
}

public void setFather_name(String father_name) {
    this.father_name = father_name;
}

public String getMother_name() {
    return mother_name;
}

public void setMother_name(String mother_name) {
    this.mother_name = mother_name;
}

public String getDob() {
    return dob;
}

public void setDob(String dob) {
    this.dob = dob;
}

public Bean() {

}
}

这是我的login_class,我在列表中添加学生的数据。

   class login_class extends activity{  
 Bean beanobj;
 List student_detail_list;
 .....
   {
        String name = getting data from response;
        ......... so on

          beanobj = new Bean();
        beanobj.studentname(name);
        beanobj.student_parent_name(parentname);
        .............so on

        }

        order_list.add(beanobj); // the details to list
        }

现在是下一个活动student_class,我想在列表视图中显示学生

public class student_class extends Activity {
ListView student_listview;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.student_list);


    student_listview = (ListView) findViewById(R.id.student_listview);



   }
    }

* == >>在login_class我创建了List student_detail_list如何在student_class类中获取它并检索数据。 谢谢

实现“类Bean实现Parcelable”。 从“login_class”转到“student_class”时,只需将“student bean数据”放入Intent中。 转到student_class后,您可以从intent获取“student bean数据”,这里是示例代码:

Intent intent = new Intent(login_class.this, student_class.class)
intent.putParcelableArrayListExtra("content", student_detail_list);
startActivity(intent);

在“student_class”中:

student_detail_list = getIntent().getParcelableArrayListExtra("content");

有很多方法可以做到这一点。

1.推荐解决方案: 如何在Android上将对象从一个活动传递到另一个活动
您可以序列化对象并将其置于意图中。 这是推荐的解决方案,但这里存在一些问题。 如果您的数据包含大量内存,则可能会在运行时使应用程序崩溃。

2.您可以将数组保存到文件中,将文件路径发送到其他活动,如URL。 在第二个活动中,读取文件并在第二个活动中创建数组。

3.我最喜欢的解决方案是为学生阵列创建一个单独的类,在你想要的任何活动中到达班级。 但是你应该小心,因为单例模式在设计上有一些问题,它也会一直留在内存中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM