我想将EditText List中的数据传递给String Array。我创建了三个类如下: ListViewStudentNames。 ListViewStudentNamesAdapter。 MainClass。 课程如下:
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;
}
}
我的主班 是
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();
}
});
}
答案 0 :(得分:1)
您可以将TextWatcher
添加到EditText,然后afterTextChanged()
更新列表中的值。
Parent_Number.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
listViewStudentNames .add(position, Parent_Number.getText().toString().trim());
}
});