Reputation: 179
How to get the values from the edit text .
Hello everyone im facing a problem with android task in which there so many edit text available in the edit text .
i need to get the values from 1 to 4 all edit texts ..? Below is my get view method of Adapter.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.social_media_row, null);
holder = new ViewHolder();
holder.social_id = (EditText) convertView.findViewById(R.id.socialMediaId);
convertView.setTag(holder);
holder.social_id.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) {
Log.i("AfterTextChange",holder.social_id.getText().toString());
}
});
} else {
holder = (ViewHolder) convertView.getTag();
}
SocialMediaModel contact = contactsList.get(position);
holder.social_id.setText(contact.getSocialMediaId());
holder.social_id.setTag(contact);
return convertView;
}
Update : i want to get the values when user click on the button
savebtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/here what i can do
}
});
Upvotes: 1
Views: 860
Reputation: 454
Declare this in your declaration
protected AdapterView.OnItemClickListener messageClickedHandler;
Click event for the list view using Adapter view
messageClickedHandler = new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView parent, View view, int position, long id) {
String strName=rowItems.get(position).getStrName();
Toast.makeText(getApplicationContext(),"Name : "+strName , Toast.LENGTH_LONG).show();
}
};
list.setOnItemClickListener(messageClickedHandler);
}
rowItems is an array list Object , getStrName() from the user defined class.
Upvotes: 0
Reputation: 77
i hope this code help you
USE Adapter cell position
follow this code
in getView(in Adapter Class)
edittext.getText().toString();
Upvotes: 0
Reputation: 3964
//at top Globally declare it
private String[] valueList = new String[];
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.social_media_row, null);
holder = new ViewHolder();
holder.social_id = (EditText) convertView.findViewById(R.id.socialMediaId);
convertView.setTag(holder);
holder.social_id.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) {
valueList[pos] = s.toString();
}
@Override
public void afterTextChanged(Editable s) {
Log.i("AfterTextChange",holder.social_id.getText().toString());
}
});
} else {
holder = (ViewHolder) convertView.getTag();
}
SocialMediaModel contact = contactsList.get(position);
holder.social_id.setText(contact.getSocialMediaId());
holder.social_id.setTag(contact);
return convertView;
}
// method to get Values
public String[] getValueList(){
return valueList;
}
Now on button click event put this code
String[] myvl = yourAdapteName.getValueList();
Upvotes: 1
Reputation: 1120
You can implement a method like this one for each EditText with the list position as parameter :
public String getValueFromFirstEditText(int position){
//here you need to recreate the id for the first editText
String result = textValues.get("theFirstEditTextAtPos:"+position);
if(result ==null)
result = "default value";
return result;
}
Upvotes: 0