1

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

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

第二:当我写完“这不起作用”时,如果我按下后退按钮,那么键盘就会消失,应用程序就会崩溃。

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

谢谢。

自定义适配器

 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
4

1 回答 1

0

您是否在 SDK 级别 16 上运行?可能与这个问题有关

还要确保您不会意外地将资源 ID 提供到 TextView 中setText()

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

在没有看到您的代码的情况下,getId()可能会返回一个 int,而您可能希望将其结果指定为字符串:

holder.id.setText(String.valueOf(getId(getItem(position))));
于 2013-04-07T12:49:11.200 回答