Android 如何从可扩展列表视图的子视图中的多个编辑文本中获取数据?
我想从可展开列表视图中获取编辑文本数据,由于我在适配器上找到了编辑文本的ID,我如何也获取活动中编辑文本的位置 这是我的密码 活动Android 如何从可扩展列表视图的子视图中的多个编辑文本中获取数据?,android,expandablelistview,Android,Expandablelistview,我想从可展开列表视图中获取编辑文本数据,由于我在适配器上找到了编辑文本的ID,我如何也获取活动中编辑文本的位置 这是我的密码 活动 public class AddNewAddressActivity extends Activity implements OnClickListener { ExpandableListAdapter listAdapter; ExpandableListView expListView; List<String>
public class AddNewAddressActivity extends Activity implements OnClickListener
{
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
//
private RelativeLayout _mainRl = null;
private RelativeLayout _rlBackToCart = null;
private LinearLayout _llPay = null;
private TextView _tvCart = null;
private TextView _tvHeader = null;
private TextView _tvPay = null;
private TextView _tvfromListTxt = null;
private TextView _tvnewoneTxt = null;
private ImageView _addNewAddressBtn = null;
private TextView _saveAddressBtn = null;
//tint
SystemBarTintManager tintManager;
private RelativeLayout _rlHeader = null;
//font
Typeface font;
int _maintainAddress = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.add_new_address_screen);
_mainRl =(RelativeLayout) findViewById(R.id.mainRl);
_rlBackToCart = (RelativeLayout) findViewById(R.id.back_to_cart_rl);
_llPay = (LinearLayout) findViewById(R.id.pay_ll);
_tvCart = (TextView) findViewById(R.id.cartTxt);
_tvHeader = (TextView) findViewById(R.id.add_new_address_headertv);
_tvPay = (TextView) findViewById(R.id.payTxt);
_tvfromListTxt = (TextView) findViewById(R.id.fromListTxt);
_tvnewoneTxt = (TextView) findViewById(R.id.newoneTxt);
_rlHeader = (RelativeLayout) findViewById(R.id.header_rl);
_addNewAddressBtn = (ImageView) findViewById(R.id.add_new_address);
_saveAddressBtn = (TextView) findViewById(R.id.saveAddressBtn);
expListView = (ExpandableListView) findViewById(R.id.exp_list);
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
// preparing list data
// prepareListData();
//font
font = Typeface.createFromAsset(getAssets(),"century_gothic.ttf");
_tvCart.setTypeface(font);
_tvHeader.setTypeface(font);
_tvPay.setTypeface(font);
_tvfromListTxt.setTypeface(font);
_tvnewoneTxt.setTypeface(font);
//on click
_rlBackToCart.setOnClickListener(this);
_llPay.setOnClickListener(this);
_addNewAddressBtn.setOnClickListener(this);
_mainRl.setOnClickListener(this);
_saveAddressBtn.setOnClickListener(this);
// changestatus bar code
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
Constant.changeStatusBarColor(AddNewAddressActivity.this);
}else {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)_rlHeader.getLayoutParams();
params.setMargins(0,28,0,0);
_rlHeader.setLayoutParams(params);
setTranslucentStatus(true);
tintManager = new SystemBarTintManager(this);
tintManager.setStatusBarTintEnabled(true);
tintManager.setStatusBarTintResource(R.color.grey);
}
}
private void setTranslucentStatus(boolean on) {
// TODO Auto-generated method stub
Window win = getWindow();
WindowManager.LayoutParams winParams = win.getAttributes();
final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
if (on) {
winParams.flags |= bits;
} else {
winParams.flags &= ~bits;
}
win.setAttributes(winParams);
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left); //for back button
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.back_to_cart_rl:
finish();
overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left); //for back button
break;
case R.id.pay_ll:
Intent _int = new Intent(AddNewAddressActivity.this, ConfirmOrderActivity.class);
startActivity(_int);
overridePendingTransition(R.anim.enter, R.anim.exit);
break;
case R.id.add_new_address:
if(listDataHeader.size()<5)
{
_maintainAddress = _maintainAddress + 1;
System.out.println("value maintain"+_maintainAddress);
listDataHeader.add("Address "+_maintainAddress);
// Adding child data
List<String> Address1 = new ArrayList<String>();
Address1.add("");
Address1.add("");
Address1.add("");
Address1.add("");
Address1.add("");
Address1.add("");
Address1.add("");
Address1.add("");
Address1.add("");
int i = _maintainAddress - 1;
listDataChild.put(listDataHeader.get(i), Address1); // Header, Child data
listAdapter = new ExpandableListAdapter(AddNewAddressActivity.this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
listAdapter.notifyDataSetChanged();
}
break;
case R.id.mainRl:
Constant.hideKeyBoard(AddNewAddressActivity.this);
break;
case R.id.saveAddressBtn:
for(int i = 0;i<listDataHeader.size();i++)
{
for (int j = 0; j < listDataChild.size(); j++)
{
}
}
break;
default:
break;
}
}
公共类AddNewAddressActivity扩展活动实现OnClickListener
{
可扩展列表适配器;
ExpandableListView解释视图;
列表列表数据头;
HashMapListDataChild;
//
私有RelativeLayout_mainRl=null;
private RelativeLayout_rlBackToCart=null;
private LinearLayout _llPay=null;
私有文本视图_tvCart=null;
私有文本视图_tvHeader=null;
私有文本视图_tvPay=null;
私有文本视图_tvfromListTxt=null;
私有文本视图_tvnewonext=null;
私有ImageView_addNewAddressBtn=null;
私有文本视图_saveAddressBtn=null;
//色调
系统经理;系统经理;
private RelativeLayout _rlHeader=null;
//字体
字体;
int _=0;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.add_new_address_screen);
_mainRl=(RelativeLayout)findViewById(R.id.mainRl);
_rlBackToCart=(RelativeLayout)findViewById(R.id.back\u to\u cart\u rl);
_llPay=(线性布局)findViewById(R.id.pay\u ll);
_tvCart=(TextView)findViewById(R.id.cartTxt);
_tvHeader=(TextView)findViewById(R.id.add\u new\u address\u headertv);
_tvPay=(TextView)findViewById(R.id.payTxt);
_tvfromListTxt=(TextView)findViewById(R.id.fromListTxt);
_TVnewOneText=(TextView)findViewById(R.id.newOneText);
_rlHeader=(RelativeLayout)findViewById(R.id.header_rl);
_addNewAddressBtn=(ImageView)findViewById(R.id.add\u new\u address);
_saveAddressBtn=(TextView)findViewById(R.id.saveAddressBtn);
expListView=(ExpandableListView)findViewById(R.id.exp\u列表);
listDataHeader=新的ArrayList();
listDataChild=newHashMap();
//准备列表数据
//prepareListData();
//字体
font=Typeface.createFromAsset(getAssets(),“century_gothic.ttf”);
_设置字体(字体);
_tvHeader.setTypeface(字体);
_设置字体(字体);
_tvfromListTxt.setTypeface(字体);
_设置字体(字体);
//点击
_rlBackToCart.setOnClickListener(this);
_llPay.setOnClickListener(此);
_addNewAddressBtn.setOnClickListener(此);
_mainRl.setOnClickListener(此);
_saveAddressBtn.setOnClickListener(此);
//更改状态条码
if(Build.VERSION.SDK\u INT>Build.VERSION\u code.KITKAT){
常量.changeStatusBarColor(AddNewAddressActivity.this);
}否则{
RelativeLayout.LayoutParams params=(RelativeLayout.LayoutParams)\ rlHeader.getLayoutParams();
参数设置边距(0,28,0,0);
_rlHeader.setLayoutParams(参数);
设置半透明状态(true);
tintManager=新系统bartintmanager(此);
tintManager.setStatusBartIntentabled(true);
tintManager.setStatusBarTintResource(R.color.Gray);
}
}
私有void setTranslucentStatus(布尔启用){
//TODO自动生成的方法存根
windowwin=getWindow();
WindowManager.LayoutParams winParams=win.getAttributes();
最终整数位=WindowManager.LayoutParams.FLAG_半透明_状态;
如果(打开){
winParams.flags |=位;
}否则{
winParams.flags&=~位;
}
win.setAttributes(winParams);
}
@凌驾
public void onBackPressed(){
//TODO自动生成的方法存根
super.onBackPressed();
overridePendingTransition(R.anim.left_至_right,R.anim.right_至_left);//用于后退按钮
}
@凌驾
公共void onClick(视图v){
开关(v.getId()){
案例R.id返回至购物车:
完成();
overridePendingTransition(R.anim.left_至_right,R.anim.right_至_left);//用于后退按钮
打破
案例R.id.pay\u ll:
Intent _int=newintent(AddNewAddressActivity.this,ConfirmOrderActivity.class);
星触觉(_int);
覆盖转换(R.anim.enter,R.anim.exit);
打破
案例R.id.添加\新\地址:
如果(listDataHeader.size(),则必须使用此方法查找单击的子编辑文本位置
// Listview on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
/*
* Toast.makeText( getActivity(), listDataHeader.get(groupPosition) + " : " + listDataChild.get( listDataHeader.get(groupPosition)) .get(childPosition),
* Toast.LENGTH_SHORT).show();
*/
String editTextData = ((EditText)v).getText().toString().trim();
return false;
}
});
在该方法中,您可以找到单击的子位置和单击的受尊重视图作为编辑文本,以及单击的组位置。
如果它能帮助你,那就接受它
您必须将数据存储到应用程序类中,才能按“保存”按钮进行访问
您可以在适配器中创建一个公共方法,该方法将返回单击的编辑文本数据
private static ArrayList<String> selectedEditTextData;
public ArrayList<String> getClickedEditTextData() {
return selectedEditTextData;
}
私有静态数组列表selectedEditTextData;
公共阵列列表getClickedEditTextData(){
返回selectedEditTextData;
}
将单击的编辑文本数据添加到getChildView
onClickListner上的ArrayList中
在应用程序类中创建一个arraylist来存储所有编辑文本视图的值,并为其生成getter和setter
在活动中,将适配器设置为列表
将值从getClickedEditTextData()
获取到活动中,并设置为全局arraylist
在应用程序类的保存按钮上使用getArraylist方法
基本上,您可以将所有输入的数据分别添加到ArrayList中并从中获取数据。我在RND之后找到了这个问题的解决方案,希望它能对其他开发人员有用
这里是适配器中的代码
全球价值
public static HashMap<String,String> arrayList = new HashMap<String,String>();
单击Save按钮,我们执行此代码
case R.id.saveAddressBtn:
for(Map.Entry m:ExpandableListAdapter.arrayList.entrySet()){
System.out.println("Dats in arralist===="+m.getKey()+" "+m.getValue());
}
//end changes
break;
garima:“活动”中有“保存”按钮
txtListChild.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
System.out.println("Value : " + childPosition +txtListChild.getText().toString());
name = childPosition+""+txtListChild.getText().toString();
if(groupPosition==0)
{
arrayList.put(String.valueOf(groupPosition),name);
}
else if(groupPosition==1)
{
arrayList.put(String.valueOf(groupPosition),name);
}
else if(groupPosition==2)
{
arrayList.put(String.valueOf(groupPosition),name);
}
else if(groupPosition==3)
{
arrayList.put(String.valueOf(groupPosition),name);
}
else if(groupPosition==4)
{
arrayList.put(String.valueOf(groupPosition),name);
}
}
});
case R.id.saveAddressBtn:
for(Map.Entry m:ExpandableListAdapter.arrayList.entrySet()){
System.out.println("Dats in arralist===="+m.getKey()+" "+m.getValue());
}
//end changes
break;