【问题标题】:Android Studio: ExpandableListView and EditTextAndroid Studio:ExpandableListView 和 EditText
【发布时间】:2018-02-18 09:56:53
【问题描述】:

我有一个带有 EditText 的 ExpandableListView。它工作得很好,但是当我在一行中输入一个数字时,该数字在另一行中也可见。我已经发现了一些关于这个问题的问题(使用支架作为解决方案),但我无法在我的情况下使用它。有谁能够帮我?

代码如下:

public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, final ViewGroup parent) {
    View view = convertView;
    if(view == null){
        LayoutInflater inflater = (LayoutInflater)this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.child_lm, parent, false);
    }
    final String childName = (String)getChild(groupPosition, childPosition);
    final TextView childItem = (TextView)view.findViewById(R.id.child_layout);
    childItem.setText(childName);


        einheit1 = data2[childPosition];
        einheit2 = data3[childPosition];
        einheit3 = data4[childPosition];
        einheit4 = data5[childPosition];
        mengenbeschreibung = data6[childPosition];


    final EditText mz= (EditText) view.findViewById(R.id.etMz);
    final String menge=mz.getText().toString();

    Drawable drawable = mz.getBackground(); 
    drawable.setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP); 
    if(Build.VERSION.SDK_INT > 16) {
        mz.setBackground(drawable); 
    }else{
        mz.setBackgroundDrawable(drawable);  
    }

    TextView eh1=(TextView)view.findViewById(R.id.tv1);
    eh1.setText(einheit1);
    TextView eh2=(TextView)view.findViewById(R.id.tv2);
    eh2.setText(einheit2);
    TextView eh3=(TextView)view.findViewById(R.id.tv3);
    eh3.setText(einheit3);
    TextView eh4=(TextView)view.findViewById(R.id.tv4);
    eh4.setText(einheit4);
    TextView mengenangabe=(TextView)view.findViewById(R.id.tvMengenbeschreibung);
    mengenangabe.setText(mengenbeschreibung);

    final View finalView1 = view;
    mz.addTextChangedListener(new TextWatcher(){
        public void afterTextChanged(
                Editable arg0) {
        }
        public void beforeTextChanged(
                CharSequence s, int start,
                int count, int after) {
        }
        public void onTextChanged(
                CharSequence s, int start,
                int before, int count) {
            TextView eh1=(TextView) finalView1.findViewById(R.id.tv1);
            TextView eh2=(TextView)finalView1.findViewById(R.id.tv2);
            TextView eh3=(TextView)finalView1.findViewById(R.id.tv3);
            TextView eh4=(TextView)finalView1.findViewById(R.id.tv4); if(mz.getText().toString().equals(null)||mz.getText().toString().equals("")) {
                }else{
                    double test10= (Math.round(Float.parseFloat(mz.getText().toString().replace(",","."))*Float.parseFloat(data2[childPosition])/100*2));
                    float test1 = (float) (test10/2);
                    eh1.setText(String.valueOf(test1));

                    double test20= (Math.round(Float.parseFloat(mz.getText().toString().replace(",","."))*Float.parseFloat(data3[childPosition])/100*2));
                    float test2 = (float) (test20/2);
                    eh2.setText(String.valueOf(test2));

                    double test30= (Math.round(Float.parseFloat(mz.getText().toString().replace(",","."))*Float.parseFloat(data4[childPosition])/100*2));
                    float test3 = (float) (test30/2);
                    eh3.setText(String.valueOf(test3));

                    double test40= (Math.round(Float.parseFloat(mz.getText().toString().replace(",","."))*Float.parseFloat(data5[childPosition])/100*2));
                    float test4 = (float) (test40/2);
                    eh4.setText(String.valueOf(test4));
                }
    });

    return view;
}

【问题讨论】:

    标签: java android android-edittext expandablelistview


    【解决方案1】:

    mz.addTextChangedListener 应该在您的 MainActivity OnCreate() 中。 至少我猜是这样,没有检查你的代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 2013-03-14
      • 1970-01-01
      • 2014-08-10
      • 2021-03-25
      相关资源
      最近更新 更多