0

I want to pass data from EditText List to a String Array. I have created three classes as the followings : ListViewStudentNames. ListViewStudentNamesAdapter. MainClass. The classes as the followings :

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


}

my Main Class is

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

        }
    });
}
6
  • Please frame your question properly as it is unclear what your problem is. Commented Mar 22, 2016 at 21:01
  • Passing the Values in the EditText to an Array Commented Mar 22, 2016 at 21:02
  • From EditText to array or vice-vers ? Commented Mar 22, 2016 at 21:03
  • And where is the EditText and which array you are talking about ? Commented Mar 22, 2016 at 21:05
  • In the Class ListViewStudentNamesAdapter Commented Mar 22, 2016 at 21:06

1 Answer 1

1

You can add TextWatcher to your EditText and in afterTextChanged() update the values in your List.

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());
            }
        });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.