0
EditText ListからString Arrayにデータを渡したいとします。私は以下のように3つのクラスを作成しました: ListViewStudentNames。 ListViewStudentNamesAdapter。 MainClass。 以下のクラス:ListViewAdapterから配列にデータを渡す
ListViewStudentNames。
public class ListViewParentsNumber {
private String StudentName ;
private String StudentID ;
private String ParentNumber ;
public String getStudentName() {
return StudentName;
}
public void setStudentName(String studentName) {
StudentName = studentName;
}
public String getStudentID() {
return StudentID;
}
public void setStudentID(String studentID) {
StudentID = studentID;
}
public String getParentNumber() {
return ParentNumber;
}
public void setParentNumber(String parentNumber) {
ParentNumber = parentNumber;
}
public ListViewParentsNumber(String StudentName, String StudentID, String ParentNumber)
{
this.ParentNumber = ParentNumber ;
this.StudentID = StudentID ;
this.StudentName = StudentName ;
}
}
ListViewStudentNamesAdapter
public class ListViewParentsNumberAdapter extends ArrayAdapter<ListViewParentsNumber> {
private Context mContext;
private ArrayList<ListViewParentsNumber> mData;
public ListViewParentsNumberAdapter (Context mContext, ArrayList<ListViewParentsNumber> mData) {
super(mContext, R.layout.parents_shape, mData);
this.mContext = mContext;
this.mData = new ArrayList<ListViewParentsNumber>();
this.mData.addAll(mData);
}
public int getCount() {
return mData.size();
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater)
mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.parents_shape, null);
}
TextView Name = (TextView) convertView.findViewById(R.id.Student_name);
Name.setText(mData.get(position).getStudentName());
EditText Parent_Number = (EditText) convertView.findViewById(R.id.Parent_Number);
Parent_Number.setText(mData.get(position).getParentNumber());
return convertView;
}
}
私のメインクラス は、あなたがあなたのEditTextとあなたのリストのafterTextChanged()
更新中の値にTextWatcher
を追加することができます
public class CHECKING_PARENTS_NUMBERS extends ActionBarActivity {
private String USERNAME ;
private String GRADE_ID ;
private String CLASS_ID ;
private Button Save ;
private String USERID ;
private Button Back ;
private String PARENTS_PHONE_NUMBERS[];
private String STUDENT_ID_ARRAY[] ;
private ListView mListView;
private ListViewParentsNumberAdapter listViewStudentNameAdapter;
private ArrayList<ListViewParentsNumber> listViewStudentNames;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_checking__parents__numbers);
mListView = (ListView) findViewById(R.id.Student_names_List);
Save = (Button) findViewById(R.id.SaveEditing) ;
Back = (Button) findViewById(R.id.Back);
new GET_PARENTS_NUMBER(USERNAME,GRADE_ID,CLASS_ID).execute();
Back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
Save.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
ListViewParentsNumber country;
for (int i = 0; i < listViewStudentNames.size(); i++) {
country = listViewStudentNames.get(i);
PARENTS_PHONE_NUMBERS[i] = country.getParentNumber() ;
}\\This Loop doesn't store the PARENTS_NUMBER IN the EditText in the array
new Update_Absence(USERNAME, GRADE_ID, CLASS_ID,PARENTS_PHONE_NUMBERS).execute();
}
});
}
問題の内容が不明確なので、適切に質問してください。 –
EditTextの値を配列に渡す – ama989
EditTextから配列またはその逆まで? –