0

I am trying to make my ListView clickable so that whenever the user clicks anywhere on the screen. An item is added to the list. Now the problem I am facing is that the listview is not scrolling.

So to solve this issue I wrapped my ListView with TouchableWithoutFeedback to make the screen clickable but unfortunately it cant be scrolled.

So to solve the scrolling issue I wrapped the whole thing under ScrollView. But the problem now I am facing is that since during the start only 1 item is there in the listview so the whole screen isn't clickable only that small portion is that the 1 item takes on the screen is clickable.

Is there a solution to this problem?

 <ScrollView>
        <Screen
          onStartShouldSetResponder={() => true}
          style={{
            flex: 1
          }}
        >
          <TouchableOpacity
            style={{ flex: 1 }}
            onPress={() => this.addMessage()}
          >
            <ListView
              data={this.state.readMessages}
              renderRow={this.renderRow}
              scrollEnabled={true}
            />
          </TouchableOpacity>
        </Screen>
      </ScrollView>

This is what I ended up in the end.

1 Answer 1

2

You can remove the scrollView as you are using ListView.

      <TouchableOpacity
        style={{ flex: 1 }}
        onPress={() => this.addMessage()}
      >
<ScrollView>
    <Screen
      onStartShouldSetResponder={() => true}
      style={{
        flex: 1
      }}
    >
        <ListView
          data={this.state.readMessages}
          renderRow={this.renderRow}
          scrollEnabled={true}
        />
    </Screen>
</ScrollView>
      </TouchableOpacity>

You can try with above code. Also one more thing, ListView is deprecated. You can use FlatList.

Sign up to request clarification or add additional context in comments.

7 Comments

if I remove ScrollView then it doesn't scroll
okays now its scrolling but when the list takes the whole view then the onPress doesnt work
Try to put alert('OnPress') and check that alert is there or not.
Yeah, the alert works until the listview takes the whole screen. then it's not clickable. I removed this prop from Screen onStartShouldSetResponder={() => true} but then the onPress wasn't called at all. Regardless of whether the listview took the whole screen or not.
You need to handle the ListView's render method and you need to put your code into it. Once ListView added. You cannot get a click.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.