菜鸟教程小白 发表于 2022-12-11 18:29:04

android - react-Native 更改平面列表中所选项目的颜色


                                            <p><p>我有一个呈现多个按钮的平面列表,我想在 esee 平面列表中标记选定的按钮,我尝试了很多东西,但在所有这些中,一旦我选择了一个,平面列表就会标记所有项目,除此之外,它不会更新,直到我更新组件中的某些内容并保存更改,然后它会进行热重新加载,这就是标记项目的显示方式</p>

<pre><code> constructor(props) {
    super(props);
    this.state = {
       pressStatus: false,
    };

    _onShowUnderlay(){
       this.setState({ pressStatus: true });
    }

    render() {
       return (
          &lt;FlatList
                  keyExtractor={this._keyExtractor}
                  data={this.state.ninosPicker}
                  renderItem={({item}) =&gt; (
                     &lt;View style={styles.hijos}&gt;
                        &lt;TouchableHighlight
                           activeOpacity={1}
                           underlayColor=&#34;#3fa9f5&#34;
                           onShowUnderlay={this._onShowUnderlay.bind(this)}
                           style={this.state.pressStatus ? styles.buttonPress : styles.botonsito }
                           onPress={() =&gt; this.setHijo(item.grado, item.grupo)}&gt;
                                 &lt;Text style={this.state.pressStatus ? styles.welcomePress : styles.titBtnGyG }&gt;{item.name}&lt;/Text&gt;
                           &lt;/TouchableHighlight&gt;
                           &lt;TouchableHighlight
                              activeOpacity={1}
                              underlayColor=&#34;#3fa9f5&#34;
                              style={this.state.pressStatus ? styles.gradosPress : styles.grados }&gt;
                                  &lt;Text style={this.state.pressStatus ? styles.welcomePress : styles.titBtnGyG }&gt;{item.grado}&lt;/Text&gt;
                           &lt;/TouchableHighlight&gt;
                           &lt;TouchableHighlight
                               activeOpacity={1}
                               underlayColor=&#34;#3fa9f5&#34;
                               style={this.state.pressStatus ? styles.grupoPress : styles.grupo }&gt;
                                 &lt;Text style={this.state.pressStatus ? styles.welcomePress : styles.titBtnGyG }&gt;{item.grupo}&lt;/Text&gt;
                           &lt;/TouchableHighlight&gt;
                     &lt;/View&gt;
                      )}/&gt;
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您必须考虑到在编码中您放置了一个唯一状态,在本例中为 this.state.pressStatus,您需要在执行时在每个对象的排列中拥有一个属性 pressStatus按钮的 Action 你必须改变那个按钮的状态</p></p>
                                   
                                                <p style="font-size: 20px;">关于android - react-Native 更改平面列表中所选项目的颜色,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/45601413/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/45601413/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: android - react-Native 更改平面列表中所选项目的颜色