问题
I have a ListView
and inside that listview , EditText
or 'CheckBox' means chekbox for the first 7 rows then Edittext is visible for other rows. Now I want the values of these rows which is clicked inside Checkbox
in first 7 rows and 'EditText' text for rest of the rows when Button is clicked.
But problem is index for the EditText and Checkbox as it is in ListView
..
How can i get value or text of all the row in single button click...
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
ViewHolder holder;
if(convertView==null){
//Inflate tabitem.xml file for each row ( Defined below )
vi = inflater.inflate(R.layout.tabitem, null);
// View Holder Object to contain tabitem.xml file elements
holder=new ViewHolder();
holder.text=(TextView)vi.findViewById(R.id.textView1);
holder.check =(CheckBox)vi.findViewById(R.id.checkBox1);
holder.text2=(EditText)vi.findViewById(R.id.editText1);
holder.text2.setTag(1);
int position12 = (Integer)holder.text2.getTag();
System.out.print(position12 + "value");
// Set holder with LayoutInflater
vi.setTag(holder);
j++;
if(j<8){
holder.text2.setVisibility(View.INVISIBLE);
holder.check.setX(-150);
}
else{
holder.check.setVisibility(View.INVISIBLE);
}
}
else {
holder=(ViewHolder)vi.getTag();
}
holder.text2.getText();
if(data.size()<=0) {
holder.text.setText("No Data");
holder.text2.getText();
// Log.v("BBBB", holder.text2.getText().toString());
}
else {
// Get each Model object from Arraylist
tempValues=null;
tempValues = (ListModel) data.get(position);
// Set Model values in Holder elements
holder.text.setText(tempValues.getCompanyName());
holder.text2.getText();
// Set Item Click Listner for LayoutInflater for each row
vi.setOnClickListener(new OnItemClickListener(position));
}
Log.v("DDD", holder.text2.getText().toString());
return vi;
}
回答1:
I recommend you to set the id to every EditText in code. Like: holder.text2.setId(position);
You should put it into your else
, I mean after this: /************ Set Model values in Holder elements ***********/
This way you will be always able to get text from all your EditText like this:
for(int i=0;i<data.size();i++){
EditText et=(EditText)vi.findViewById(i);
if(et!=null)
//Get the text from EditText
}
来源:https://stackoverflow.com/questions/23321195/edittext-checkbox-text-value-inside-the-listview