Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 获取约30个EditText/Seekbar的参考,并为其提供单独的侦听器_Android - Fatal编程技术网

Android 获取约30个EditText/Seekbar的参考,并为其提供单独的侦听器

Android 获取约30个EditText/Seekbar的参考,并为其提供单独的侦听器,android,Android,我是android开发的新手,目前我有一个包含5个片段的简单滑动表格布局,每个片段都有一个垂直线性布局,大约有20-30个水平线性布局,带有文本视图(SeekBar)和编辑文本/开关 Layoutsnippet: <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content">

我是android开发的新手,目前我有一个包含5个片段的简单滑动表格布局,每个片段都有一个垂直线性布局,大约有20-30个水平线性布局,带有文本视图(SeekBar)和编辑文本/开关

Layoutsnippet:

    <LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:text="Setting1"
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:layout_weight="3"/>

    <SeekBar
        android:id="@+id/seekBar"
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:max="50"
        android:progress="25" />

    <Switch
        android:id="@+id/switch1"
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:layout_weight="3"/>
</LinearLayout>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:text="Setting2"
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:layout_weight="3"/>

    <SeekBar
        android:id="@+id/seekBar2"
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:layout_weight="4"
        android:max="50"
        android:layout_gravity="center_vertical"
        android:progress="25" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="0px"
        android:layout_height="wrap_content"
        android:gravity="right"
        android:layout_weight="3"
        android:inputType="numberSigned"/>
</LinearLayout>
一遍又一遍


非常感谢您的帮助!:)

你可能想调查一下。您可以将逻辑封装到复合视图中并多次重用它

    sw1 = (Switch) findViewById(R.id.switch1);
    et1 = (EditText) findViewById(R.id.editText1);
    sb1 = (SeekBar) findViewById(R.id.seekBar2);
    sb1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean 
        fromUser) {
            et1.setText(Integer.toString(progress));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
    et1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            sb1.setProgress(Integer.parseInt(et1.getText().toString()));
        }
    });