Как увеличить количество прядильщиков по значению ключа пользователя - PullRequest
0 голосов
/ 10 января 2019

Как добавить количество прядильщиков по заполнению пользователем в строке категории?

вот мой код в фрагменте. пожалуйста, помогите мне.

 public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View rootView = inflater.Inflate(Resource.Layout.Category1, container, false);
        txtCat1Name = (EditText)rootView.FindViewById(Resource.Id.txtCat1Name);
        txtCat1Length = (EditText)rootView.FindViewById(Resource.Id.txtCat1Length);
        txtCat1Line = (EditText)rootView.FindViewById(Resource.Id.txtCat1Line);
        btnSaveCat1 = (Button)rootView.FindViewById(Resource.Id.btnSaveCat1);

        noOfLine = Int16.Parse(txtCat1Line.Text);
        btnSaveCat1.Click += btnSaveCat1_click;
        txtCat1Line.KeyPress += txtCat1Line_KeyPress;


        return rootView;
    }

 private void txtCat1Line_KeyPress(object sender, View.KeyEventArgs e)
    {
        var spinners = new Spinner[0];
        if (e.Event.Action == KeyEventActions.Up && txtCat1Line.Text.Length > 0)
        {
            for (int i = 0; i < noOfLine; i++)
            {
                var spinner = new Spinner(this.Activity);

                spinners[i] = spinner;
            }

        }
}

как добавить счетчик по ключу пользователя в строке категории. enter image description here

1 Ответ

0 голосов
/ 11 января 2019

Вы можете определить макет корня для Xaml rootView с идентификатором:

например, ваш Layout.Category1

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id = "@+id/root_layout"
>
   ....
</LinearLayout>

затем во фрагменте:

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    View rootView = inflater.Inflate(Resource.Layout.Category1, container, false);
    txtCat1Name = (EditText)rootView.FindViewById(Resource.Id.txtCat1Name);
    txtCat1Length = (EditText)rootView.FindViewById(Resource.Id.txtCat1Length);
    txtCat1Line = (EditText)rootView.FindViewById(Resource.Id.txtCat1Line);
    btnSaveCat1 = (Button)rootView.FindViewById(Resource.Id.btnSaveCat1);
    rootLayout = rootView.FindViewById<LinearLayout>(Resource.Id.root_layout);
    btnSaveCat1.Click += btnSaveCat1_click;
    txtCat1Line.KeyPress += txtCat1Line_KeyPress;


    return rootView;
}


private void txtCat1Line_KeyPress(object sender, View.KeyEventArgs e)
    {


        e.Handled = false;
        if (TextUtils.IsEmpty(txtCat1Line .Text))
        {
            return;
        }
        noOfLine = Int16.Parse(txtCat1Line .Text);
        if (e.Event.Action == KeyEventActions.Down && e.KeyCode == Keycode.Enter)
        {
            for (int i = 0; i < noOfLine; i++)
            {
                var spinner = new Spinner(this.Activity);
                layout.AddView(spinner);
                e.Handled = true;
            }
        }
    }

EditText xaml :

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id = "@+id/txtCat1Line"
    android:imeOptions="actionGo"
    android:inputType="number"
/>

Код ответа в основном обеспечивает метод динамического сложения Spinner, и здесь я рекомендую не прослушивать событие KeyPress (может быть, вы могли бы добавить кнопку для запуска или прослушать фокус и так далее).

...