0
확장 가능한 ListView를 사용하고 있습니다. 모든 하위 항목에 하나의 EditText가 있습니다. list_item.xml :Expandable ListView의 EditText ID 가져 오기
나는 사용자에 의해 입력 된 모든 아이의 글고의 텍스트를 얻기 위해 원하는 버튼을 클릭 mainActivity, 에 버튼이 있습니다<TextView
android:id="@+id/lblListItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="TextView"
android:textColor="#000000"
android:textSize="17dp" />
<EditText
android:id="@+id/marks"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Obtained"
android:inputType="number"
android:maxLines="1"
tools:layout_editor_absoluteX="142dp"
tools:layout_editor_absoluteY="60dp" />
, 내가 시도 :
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
TextView txtListChild = (TextView) convertView.findViewById(R.id.lblListItem);
edt=(EditText)convertView.findViewById(R.id.marks);
String abc=edt.getText().toString();
Toast.makeText(convertView.getContext(),"This: "+ abc,Toast.LENGTH_SHORT).show();
txtListChild.setText(childText);
return convertView;
}
하지만, 그룹이 확장 된 경우에만 작동합니다. (Toast는 내가 EditText에 쉽게 있던 텍스트를 보여줍니다.) 사용자가 버튼을 눌렀을 때가 아닙니다.
그래서 버튼 클릭에서 getChildView 메소드를 호출하려면 어떻게해야합니까?OnClick()에서 어떤 인수를 전달해야할지 모르겠습니다. 또는
어쩌면 해킹은 작동합니다 : 버튼을 클릭하면 확장 된 그룹은 축소 및 확장, 그래서 내가 원하는 일을 할 것입니까? 아마도
내가 모든 하위 항목의 텍스트 싶어. (루프에있을 수도 있음) 하지만 getView()에는 루프가없고 잘 작동합니다 (그룹이 확장되었을 때만 작동합니다). –
글쎄, 하나의 버튼이어야합니다. 그리고 말하지만, 좋은 접근 방식은, 내가 생각하기에, 이유 : 일부 EditTexts가 null 일 수 있습니다? 아마도. 그러면 사용자를 제한 할 수 있습니다. 버튼은 모든 필드가 채워진 경우에만 작동합니다. 그래서 One ButtonClick에서 참조를 보유하고 모든 값을 전달하는 방법을 알려주십시오. –
텍스트를 가져 오는 순서는 표시되는 순서대로 이루어져야합니다. 내 말은 Toast가 위의 코드에서 보여주는 것과 동일합니다. –