How to edit listview

kotlin · · 116 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Can anyone point me in the right direction on how to edit listviews? E.g. edit the text in each row individually, as well as how to add or delete a whole row of the list?</p> <hr/>**评论:**<br/><br/>bbqburner: <pre><p>Android? Look for adapters e.g. <a href="https://github.com/codepath/android_guides/wiki/Using-an-ArrayAdapter-with-ListView" rel="nofollow">ArrayAdapter</a>, or the more recommended <a href="https://developer.android.com/guide/topics/ui/layout/recyclerview.html" rel="nofollow">RecyclerView</a>.</p> <p>That CodePath site also has a whole section on it: <a href="https://guides.codepath.com/android#adapterviews" rel="nofollow">https://guides.codepath.com/android#adapterviews</a></p></pre>KotlinN00b: <pre><p>Thanks for the link theres some good info in there. Specifically i want to edit the list/recyclerview while in the app. E.g. add in tasks for me to complete. Do you know anything which shows that?</p></pre>bbqburner: <pre><p>When it comes to adapters, its pretty much:</p> <ol> <li><p>what you do with your dataset </p></li> <li><p>notifying the adapter that the dataset its holding has changed.</p></li> </ol> <p>e.g. A view onClick will invoke <code>list.remove(item)</code> and then calling <code>adapter.notifyXchanged</code> where X can be <code>dataset</code>, <code>item</code> etc. Check the adapter you are using for its proper notify methods. If you need search terms, then <code>Android notify list/recycler adapter</code>. </p> <p>The default nuclear trigger is simply calling <code>adapter.notifyDataSetChanged</code>. For RecyclerView you can read <a href="https://guides.codepath.com/android/Using-the-RecyclerView#notifying-the-adapter" rel="nofollow">these</a> (also read using the DiffUtil below it). Also, this is not really Kotlin related and <a href="/r/androiddev" rel="nofollow">/r/androiddev</a> or StackOverflow is the proper avenue for this question.</p></pre>sneakpeekbot: <pre><p>Here&#39;s a sneak peek of <a href="/r/androiddev" rel="nofollow">/r/androiddev</a> using the <a href="https://np.reddit.com/r/androiddev/top/?sort=top&amp;t=year" rel="nofollow">top posts</a> of the year!</p> <p>#1: <a href="https://gfycat.com/VigorousPleasedHuman" rel="nofollow">LPT: Drag up and down on process windows to accelerate gradle downloads</a> | <a href="https://np.reddit.com/r/androiddev/comments/71xljr/lpt_drag_up_and_down_on_process_windows_to/" rel="nofollow">50 comments</a><br/> #2: <a href="https://i.imgur.com/nQRdRR2.png" rel="nofollow">As a developer of a free game, people like this grind my gears</a> | <a href="https://np.reddit.com/r/androiddev/comments/736tf5/as_a_developer_of_a_free_game_people_like_this/" rel="nofollow">161 comments</a><br/> #3: <a href="https://np.reddit.com/r/androiddev/comments/6bqlds/kotlin_is_officially_supported_on_android/" rel="nofollow">Kotlin is officially supported on Android</a></p> <hr/> <p><sup><sup>I&#39;m</sup></sup> <sup><sup>a</sup></sup> <sup><sup>bot,</sup></sup> <sup><sup>beep</sup></sup> <sup><sup>boop</sup></sup> <sup><sup>|</sup></sup> <sup><sup>Downvote</sup></sup> <sup><sup>to</sup></sup> <sup><sup>remove</sup></sup> <sup><sup>|</sup></sup> <a href="https://www.reddit.com/message/compose/?to=sneakpeekbot" rel="nofollow"><sup><sup>Contact</sup></sup> <sup><sup>me</sup></sup></a> <sup><sup>|</sup></sup> <a href="https://np.reddit.com/r/sneakpeekbot/" rel="nofollow"><sup><sup>Info</sup></sup></a> <sup><sup>|</sup></sup> <a href="https://np.reddit.com/r/sneakpeekbot/comments/7o7jnj/blacklist/" rel="nofollow"><sup><sup>Opt-out</sup></sup></a></p></pre>Tired_Acrobat: <pre><p>Check this video : <a href="https://youtu.be/jS0buQyfJfs" rel="nofollow">https://youtu.be/jS0buQyfJfs</a></p></pre>KotlinN00b: <pre><p>Thanks for the link. Thats a good tutorial but it doesnt show how to edit the names of the list within the app? Do you know of anything which teaches that?</p></pre>Tired_Acrobat: <pre><p>You just add an item to the array and then call a methode that updates the list, like that :</p> <pre><code> yourArray.add(YourObject) yourRecyclerView.adapter.notifyDataSetChanged() </code></pre> <p>you can use this code in the onCreate() or anywhere you want , you just need to have access to yourArray and yourRecyclerView. And also if you want to show like int or strings there is no need to create a custom adapter or view handler.</p> <p>Finding a tutorial that explaining those things in Kotlin is hard, because the language is new (in the android world), but knowing how to read java will help you solve your problems because they use the same SDK. I actually found out how to do that by reading java code.</p></pre>
116 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet