【问题标题】:Can't get Input from EditText inside a fragment无法从片段内的 EditText 获取输入
【发布时间】:2016-07-22 12:39:26
【问题描述】:

我正在制作一个可以显示不同产品图像的应用程序,并且有一个按钮可以选择它们,这个按钮会将信息发送到localhost

但是,EditText 不起作用。如果我这样做了

ItemNote=(EditText) imageLayout.getActivity().findViewById(R.id.ItemNote);

它将起作用,但仅适用于该选项,并且再次停止适用于不同的选项。

    @Override
    public Object instantiateItem(ViewGroup view, int position) {
        View imageLayout = inflater.inflate(R.layout.item_pager_image, view, false);
        assert imageLayout != null;

        ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);

         ItemNote=(EditText) imageLayout.findViewById(R.id.ItemNote);
         ItemQuantity=(EditText)imageLayout.findViewById(R.id.ItemQuantity);

         ItemName=(TextView) imageLayout.findViewById(R.id.ItemName);
         ItemPrice=(TextView)imageLayout.findViewById(R.id.ItemPrice);

         choose=(Button) imageLayout.findViewById(R.id.choose);
            quantity=ItemQuantity.getText().toString();
            note=ItemNote.getText().toString();
            name=ItemName.getText().toString();
            price=ItemPrice.getText().toString();
         choose.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                //getting input for item quantity and Item Extraa note
                String Order= " "+name+" "+'('+quantity+')'+" With "+note+" Price : "+price+'\n';
                ItemNote.setText(""); // Reset the text field to blank
                ItemQuantity.setText(""); // Reset the text field to blank
                messsage = Order; // get the text message on the text field
                SendMessage sendMessageTask = new SendMessage();
                sendMessageTask.execute();
            }
        });

【问题讨论】:

    标签: android android-edittext localhost


    【解决方案1】:

    您需要阅读 onClick 内部的注释。当前,您正在读取 instantiateItem 中的文本,因此仅在调用该方法时才获取文本。您需要在单击按钮时获取文本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多