Как получить значения из EditText AndroidAndroid

Форум для тех, кто программирует под Android
Anonymous
Как получить значения из EditText Android

Сообщение Anonymous »

У меня есть куча полей EditText , и я пытаюсь получить их значения. Но это возвращает пустые строки. Вот мой код: < /p>

Код: Выделить всё

public class add_product_fragment extends Fragment implements AdapterView.OnItemSelectedListener{

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_add_product, container, false);

mName = view.findViewById(R.id.productName);
productName = mName.getText().toString().trim();

mPrice = view.findViewById(R.id.productPrice);
productPrice = mPrice.getText().toString().trim();

mDescription = view.findViewById(R.id.productDescription);
productDescription = mDescription.getText().toString().trim();

mQuantity = view.findViewById(R.id.productQuantity);
productQuantity = mQuantity.getText().toString().trim();

addToInventory = view.findViewById(R.id.addToInventoryBtn);

addToInventory.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
System.out.println(productName + ", " + productDescription + ", " + productType
+ ", " + productPrice + ", " + productQuantity);
}
});

return view;
}
он не работает из -за фрагмента s или я что -то упускаю?

Подробнее здесь: https://stackoverflow.com/questions/650 ... xt-android

Вернуться в «Android»