ListView应用程序中的EditText崩溃

时间:2013-04-07 12:10:14

标签: android android-listview android-edittext

我在同一个活动上有2个listView,每行都有一个EditText。

  

第一个问题:每当我尝试在一个的EditText中写一些东西   行文本要么没有显示,要么用一种奇怪的语言。

     

第二:当我完成了写“哪个不工作”,如果我按下   后退按钮使键盘消失,应用程序崩溃。

另一方面,如果我按下EditText,键盘出现并按下而不写任何东西就可以正常工作..

感谢。

CustomAdapter

 public View getView(final int position, View convertView, ViewGroup parent) {
        System.out.println("getView " + position + " " + convertView);
        final OrderHolder holder;

        if (convertView == null) {
            mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            convertView = mInflater.inflate(l, null);

            holder  = new OrderHolder();

            holder.id = (TextView)convertView.findViewById(R.id.oid);
            holder.name = (TextView)convertView.findViewById(R.id.oname);
            holder.price = (TextView)convertView.findViewById(R.id.oprice);
            holder.btn = (Button) convertView.findViewById(R.id.oorder);
            holder.quantity = (TextView) convertView.findViewById(R.id.quantity);
            holder.customise = (EditText) convertView.findViewById(R.id.customize);



            convertView.setTag(holder);
        }

        else {
            holder = (OrderHolder)convertView.getTag();

        }

        holder.id.setText(getId(getItem(position)));
        holder.name.setText(getName(getItem(position)));
        holder.price.setText("£ " + getPrice(getItem(position)));
        holder.customise.setText("");

        if(pos.containsKey(position))
        {
            holder.customise.setText(pos.get(position));                 

        }

                holder.quantity.setVisibility(View.VISIBLE);


            holder.btn.setOnClickListener(new View.OnClickListener(){
                 public void onClick(View v) {

                  HashMap<String, String> map = getItem(position);


              if(v.getId() == R.id.order)
             {

                  if ( orderList.contains(getItem(position)) ){
                      System.out.println("item :" +getItem(position));
                      //holder.quantity.setText("q");
                      int foo = Integer.parseInt(map.get(TAG_QUANTITY).toString());

                      map.put(TAG_QUANTITY, "" + (foo-1));
                      if((foo-1)==0)
                      {
                          orderList.remove(getItem(position));
                      }

                  }


                  ((MyOrderAdapter)  list1.getAdapter()).notifyDataSetChanged();
                  ((MyOrderAdapter)  list11.getAdapter()).notifyDataSetChanged();

                          Float fo = Float.parseFloat(map.get(TAG_PRICE).toString());
                          Float total = Float.parseFloat(t.getText().toString());

                          //System.out.println("heeeeeeeeeeeeeere :" +fo);
                          t.setText(""+ String.format("%.2f", (total-fo)));
                  }
            }
          });
            holder.btn.setOnLongClickListener(new View.OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                      Float fo = Float.parseFloat((getItem(position).get(TAG_PRICE)).toString());
                      Float Quant = Float.parseFloat((getItem(position).get(TAG_QUANTITY)).toString());
                      Float total = Float.parseFloat(t.getText().toString());
                      //System.out.println("heeeeeeeeeeeeeere :" +fo);
                      orderList.remove(getItem(position));
                      t.setText(""+ String.format("%.2f", (total-(fo*Quant))));
                      ((MyOrderAdapter) list1.getAdapter()).notifyDataSetChanged();
                      ((MyOrderAdapter) list11.getAdapter()).notifyDataSetChanged();
                    return false;
                }
            });



        holder.quantity.setText(getQuant(getItem(position)));
        return convertView;
    }

LOGCAT

04-07 13:16:24.126: I/Editor(16815): setup window support handles
04-07 13:16:24.126: I/Editor(16815): setup window support handles
04-07 11:52:33.618: E/AndroidRuntime(16268): FATAL EXCEPTION: main
04-07 11:52:33.618: E/AndroidRuntime(16268): java.lang.IndexOutOfBoundsException
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.graphics.Paint.getTextRunAdvances(Paint.java:1832)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.graphics.Paint.getTextRunAdvances(Paint.java:1809)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.text.TextLine.handleText(TextLine.java:759)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.text.TextLine.handleRun(TextLine.java:910)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.text.TextLine.measureRun(TextLine.java:414)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.text.TextLine.measure(TextLine.java:293)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.text.TextLine.metrics(TextLine.java:267)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.text.Layout.getLineExtent(Layout.java:952)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.text.Layout.getLineWidth(Layout.java:918)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.TextView.desired(TextView.java:6191)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.TextView.onMeasure(TextView.java:6257)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.View.measure(View.java:15479)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4824)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.TableRow.measureChildBeforeLayout(TableRow.java:247)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1038)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.TableRow.onMeasure(TableRow.java:114)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.View.measure(View.java:15479)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4824)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.View.measure(View.java:15479)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.ListView.setupChild(ListView.java:1847)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.ListView.makeAndAddView(ListView.java:1762)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.ListView.fillSpecific(ListView.java:1318)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.ListView.layoutChildren(ListView.java:1633)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.AbsListView.onLayout(AbsListView.java:2296)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.View.layout(View.java:14061)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewGroup.layout(ViewGroup.java:4372)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1644)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.TableRow.onLayout(TableRow.java:123)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.View.layout(View.java:14061)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewGroup.layout(ViewGroup.java:4372)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.View.layout(View.java:14061)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewGroup.layout(ViewGroup.java:4372)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.View.layout(View.java:14061)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewGroup.layout(ViewGroup.java:4372)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.View.layout(View.java:14061)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewGroup.layout(ViewGroup.java:4372)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.View.layout(View.java:14061)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewGroup.layout(ViewGroup.java:4372)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.View.layout(View.java:14061)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewGroup.layout(ViewGroup.java:4372)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1655)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1513)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1426)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.View.layout(View.java:14061)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewGroup.layout(ViewGroup.java:4372)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.View.layout(View.java:14061)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewGroup.layout(ViewGroup.java:4372)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1984)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1805)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1105)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4462)
04-07 11:52:33.618: E/AndroidRuntime(16268):    at android.view.Choreograph

1 个答案:

答案 0 :(得分:0)

您是否在SDK级别16上运行? It may be related to this problem

另外请确保您不会意外地将资源ID提供给TextView的setText()

holder.id.setText(getId(getItem(position)));

如果没有看到您的代码,getId()可能会返回一个int,而您可能希望将其结果指定为String:

holder.id.setText(String.valueOf(getId(getItem(position))));