모든 하위 항목에 EditText가있는 확장 가능 ListView (EXLV)가 있으며 EXLV 외부에 Button이 있습니다. 내가 일을 망쳤다. 값을 가져오고 싶습니다. 버튼 클릭시 EditTexts에 입력 한 데이터입니다. 입력 한 값이 다시 생성되므로 (이유를 모르겠 음). 도움말은 매우 감사하게 생각합니다. https://drive.google.com/file/d/1YsCb23-wL_KBgj2braqT59mPezRhSS28/view?usp=sharingExpandable ListView에서 하위 값 가져 오기
MainActiviy.java :
package com.lvexpandable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Handler;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ExpandableListView.OnGroupCollapseListener;
import android.widget.ExpandableListView.OnGroupExpandListener;
import android.widget.Toast;
public class MainActivity extends Activity {
final int snnn=1857;
Button btn;
EditText edt;
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] mStrings = new String[20];
// get the listview
expListView = (ExpandableListView) findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
}
public void btnClick(View v){
//I want to get values entered in EditTexts here. Maybe using SharedPref, in a List<> or whatever.
}
/*
* Preparing the list data
*/
private void prepareListData() {
listDataHeader = new ArrayList<>();
listDataChild = new HashMap<>();
// Adding child data
listDataHeader.add("PG");
listDataHeader.add("Nursery");
// Adding child data
List<String> pg = new ArrayList<String>();
pg.add("PG1: ");
pg.add("PG2: ");
pg.add("PG3: ");
pg.add("PG4: ");
pg.add("PG5: ");
pg.add("PG6: ");
pg.add("PG7: ");
pg.add("PG8: ");
pg.add("PG9: ");
pg.add("PG10: ");
pg.add("PG11: ");
pg.add("PG12: ");
pg.add("PG13: ");
pg.add("PG14: ");
pg.add("PG15: ");
List<String> nur = new ArrayList<String>();
nur.add("Object A ");
nur.add("Obj B: ");
nur.add("Obj C:");
listDataChild.put(listDataHeader.get(0), pg); // Header, Child data
listDataChild.put(listDataHeader.get(1), nur);
}
}
ExpandableListAdapter.java :
package com.lvexpandable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public ExpandableListAdapter(Context context, List<String> listDataHeader,
HashMap<String, List<String>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@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 = convertView.findViewById(R.id.lblListItem);
txtListChild.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
activity_main.xml :
여기 이 경우 전체 프로젝트에 대한 링크입니다 ,223,174,사람이 혼란이있는 경우, 당신이하려고하는 것은 물론 가능하다
참조하십시오 내 대답 –
이 더 childviews 와트없이 당신의 EditText에서 값을 얻어서 의미합니까 각 groupview :
이제 버튼 클릭처럼 될 것인가? expandablelistview에서 여러 그룹 뷰의 입력 된 모든 childview edittext 데이터가 필요합니까? –
예, 모든 값이지만 여러 개의 그룹 뷰가 아닌 모든 값입니다. 하나의 세션 동안 마지막 확장 그룹의 모든 EditText 값만 필요합니다. –