如何在更改活动时更改edittext值

时间:2016-04-06 07:04:43

标签: android android-edittext expandablelistview

假设有太多的Expandablelistview,其中很多Expandablelistview Group都有Edittext和Button,而有些则没有哪个Group没有Edittext和Button,那么Child正在使用Edittext和Button。在Click of Button中我通过传递edittext值来更改Activity。

在另一个Activity中,我更改了它的值,当我回到该活动时,Edittext值应该更改。

@Override
public View getChildView(final int groupPosition, final int childPosition,
                         boolean isLastChild, View convertView, ViewGroup parent) {

    final ExpandableChild child = (ExpandableChild) getChild(groupPosition, childPosition);
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_item, null);
    }
    final ViewHolder viewHolder = new ViewHolder();

    viewHolder.rl = (RelativeLayout) convertView.findViewById(R.id.rl);
    viewHolder.rl1 = (RelativeLayout) convertView.findViewById(R.id.rl1);

    if (child.getCurcod() == null) {
        viewHolder.rl1.setVisibility(View.VISIBLE);
        viewHolder.rl.setVisibility(View.GONE);
    } else {
        viewHolder.rl1.setVisibility(View.GONE);
        viewHolder.rl.setVisibility(View.VISIBLE);
        viewHolder.editText = (EditText) convertView.findViewById(R.id.editText);
        viewHolder.mod = (TextView) convertView.findViewById(R.id.textView14);

        viewHolder.mod.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    Intent fgj = new Intent(context, TwoActivity.class);
                    fgj.putExtra("child", "child");
                    fgj.putExtra("grouppos",groupPosition);
                    fgj.putExtra("childpos",childPosition);
                    fgj.putExtra("qty", viewHolder.editText.getText().toString());
                    context.startActivity(fgj);
            }
        });

    return convertView;
}

@Override
public View getGroupView(final int groupPosition, boolean isExpanded,
                         View convertView, ViewGroup parent) {
    final ExpandableGroup group = (ExpandableGroup) getGroup(groupPosition);
    if (convertView == null) {
        LayoutInflater inf = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        convertView = inf.inflate(R.layout.list_item, null);
    }
    final ViewHolder viewHolder = new ViewHolder();

    viewHolder.rl = (RelativeLayout) convertView.findViewById(R.id.rl);
    viewHolder.rl1 = (RelativeLayout) convertView.findViewById(R.id.rl1);

    if (group.getCurcod() == null) {
        viewHolder.rl1.setVisibility(View.VISIBLE);
        viewHolder.rl.setVisibility(View.GONE);
        viewHolder.itemNameGrp = (TextView) convertView.findViewById(R.id.itemGrp);

        viewHolder.itemNameGrp.setText(group.getItmnam());

    } else {
        viewHolder.rl1.setVisibility(View.GONE);
        viewHolder.rl.setVisibility(View.VISIBLE);
        viewHolder.editText = (EditText) convertView.findViewById(R.id.editText);
        viewHolder.mod = (TextView) convertView.findViewById(R.id.textView14);

        viewHolder.mod.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (viewHolder.editText.getText().toString().equals("0") || viewHolder.editText.getText().toString().equals("")) {
                    Toast.makeText(context, "Quantity cannot be empty or Zero", Toast.LENGTH_SHORT).show();
                } else {
                    Intent fgj = new Intent(context, TwoActivity.class);
                    fgj.putExtra("child", "group");
                    fgj.putExtra("grouppos",groupPosition);
                    fgj.putExtra("childpos",0);
                    fgj.putExtra("qty", viewHolder.editText.getText().toString());
                    context.startActivity(fgj);
                }
            }
        });

    return convertView;
}

当我在edittext框中输入一些值并滚动页面时,值会更改或在另一个edittext框中输入

1 个答案:

答案 0 :(得分:0)

您可以使用共享首选项添加/更新值!!