无法从片段内的EditText获取输入

时间:2016-07-22 12:39:27

标签: android android-edittext localhost

我正在创建一个可以显示不同产品图片的应用,并且有一个按钮可以选择它们,此按钮会将信息发送到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();
            }
        });

1 个答案:

答案 0 :(得分:0)

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

相关问题