2017-03-19 10 views
1

私は2つのクラスを持っていますが、login_classは2番目にstudent_classです。リストにデータを追加し、次のページのデータを使用してリストビューで表示する方法

私はログインする必要があります。応答で、私はstudent_mother_nameなど、 student_name、student_srno、student_father_nameのような学生の詳細を取得

この私の豆です(ゲッターセッター)クラス

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); 



    } 
    } 

* == >>私は私student_classクラスでそれを取得し、取得する方法List student_detail_listを作成しましたlogin_classにデータ。 ありがとう

答えて

0

「クラスBeanはParcelableを実装します」を実現します。 "login_class"から "student_class"に行くときは、インテント内に "生徒の豆データ"を入れてください。 student_classしようとした後、あなたが意図から、「学生の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"); 
0

やるべきことがたくさんの方法があります。それ。

1.推奨する解決策:How to pass an object from one activity to another on Android
オブジェクトをシリアル化してインテントに入れることができます。これは推奨される解決策ですが、ここにいくつかの問題があります。データに大量のメモリが含まれていると、実行時にアプリケーションがクラッシュする可能性があります。

2.配列をファイルに保存し、ファイルパスをURLのように他のアクティビティに送信できます。 2番目のアクティビティでファイルを読み、2番目のアクティビティで配列を作成します。

3.私の好きな解決策は、生徒用配列のためのシングルトンクラスを作成し、必要なアクティビティでクラスに到達することです。しかし、シングルトンパターンには設計上の問題もあり、常にメモリに残るため注意が必要です

関連する問題