{"id":30165,"date":"2023-01-13T15:34:57","date_gmt":"2023-01-13T10:04:57","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/"},"modified":"2023-01-13T15:34:57","modified_gmt":"2023-01-13T10:04:57","slug":"solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/","title":{"rendered":"[Solved] If i click on edit button particular row data should be fetch in listview?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-32265864\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"32265864\" data-parentid=\"32265375\" data-score=\"1\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>With out code I can not help you but I think you do not have the direction or road map . let me show you the road map so that you know how to achieve what you want to do :<\/p>\n<ol>\n<li>\n<p>implement the click listener on list view. the click should be according to your need such as simple click or a long press or you get set item click listener. <\/p>\n<\/li>\n<li>\n<p>In click listner you can get the index easily and use index to get the item Id from the model class (if you have custom adapter and array )<\/p>\n<\/li>\n<li>\n<p>now you have the index you got the Id , and Id is the key in the database to get the Data from the row. so You have id you can get the data and show that data into the activity where user can edit those values <\/p>\n<p>this is just the demo code so that you can get the idea , in my case I have this function in Database And I was getting\/ retrieving the array list in the following manner <\/p>\n<p>public ArrayList GetData(String Name)  {<\/p>\n<blockquote>\n<pre><code>  ArrayList&lt;Detail&gt; list = new ArrayList&lt;Detail&gt;();\n    cursor = db.rawQuery(\"select * from MosqueDataNew where Name=\"\"\n            + Name + \"\"\", null);\n    if (cursor != null &amp;&amp; cursor.getCount() &gt; 0) {\n        cursor.moveToFirst();\n        list.add(new Detail(\n                cursor.getString(cursor.getColumnIndex(\"ID\")),\n                cursor.getString(cursor.getColumnIndex(\"Name\")),\n                cursor.getString(cursor.getColumnIndex(\"LatitudeLocation\")),\n                cursor.getString(cursor.getColumnIndex(\"LongitudeLocation\")),\n                cursor.getString(cursor.getColumnIndex(\"Size\"))));\n        return list;\n    }\n    return null;\n}\n<\/code><\/pre>\n<\/blockquote>\n<\/li>\n<\/ol>\n<p>so this is the way to get the idea to how to retrieve data from the specific row.<\/p>\n<ol start=\"5\">\n<li>Now after getting the editions from the user you can save the values again at the same id so to update the data for this you have to implement the update method in the database. and call that function the Update button click listener. <\/li>\n<\/ol>\n<p>public boolean UpdateData(ContentValues contentValues, String id) {<\/p>\n<pre><code>if (db.update(\"YourTableName\", contentValues, \"ID = '\" + id + \"'\",      null) &gt; 0) {\nreturn true;\n}\nreturn false;}\n<\/code><\/pre>\n<p>content values are the new updated values you want to save in that place. <\/p>\n<p><strong>Part 2<\/strong><br \/>\nAs You want to edit the values in new activity by clicking on the button of each row , you can achieve it  the way if you pass the context to the adapter while creating it, because for opening new activity which you want to use for editing the values, You must have context to start a new activity , this is how you can do it :<\/p>\n<pre><code>public class MyAdapter extends Adapter {\n     private Context context;\n\n     public MyAdapter(Context context) {\n          this.context = context;     \n     }\n\n     public View getView(...){\n         View v;\n         v.setOnClickListener(new OnClickListener() {\n             void onClick() {\n                 context.startActivity(...);\n             }\n         });\n     }\n}\n<\/code><\/pre>\n<p>so as you can see in this you are using to start the activity you wanted to open , so it is clear now how to navigate to new activity , but before doing this you need to get all of the data from database to edit, so this is how you do in button click before opening the new activity <\/p>\n<p>In your getView method of adapter you have to put your click listener which would work for each row , you need to get the id of your item list and then pass it on to database function which is getting all the data for specific Id <\/p>\n<pre><code>editButton.setOnClickListener(new View.OnClickListener() {\n\n            @Override\n            public void onClick(View arg0) {\n                \/\/get id of itemlist , or array what ever datamodel you are using  and use it to fetch the data from the database\n\n            }\n        });\n<\/code><\/pre>\n<blockquote>\n<p>Edit Part 3<\/p>\n<\/blockquote>\n<p>If you want to get the data on basis of id then upper defined function of database would be changed a little bit, here is hows it goes <\/p>\n<pre><code>public ArrayList GetData(String id) {\n\n  ArrayList&lt;Detail&gt; list = new ArrayList&lt;Detail&gt;();\n    cursor = db.rawQuery(\"select * from MosqueDataNew where id = '\"\n            + ID + \"'\", null);\n    if (cursor != null &amp;&amp; cursor.getCount() &gt; 0) {\n        cursor.moveToFirst();\n        list.add(new Detail(\n                cursor.getString(cursor.getColumnIndex(\"ID\")),\n                cursor.getString(cursor.getColumnIndex(\"Name\")),\n                cursor.getString(cursor.getColumnIndex(\"LatitudeLocation\")),\n                cursor.getString(cursor.getColumnIndex(\"LongitudeLocation\")),\n                cursor.getString(cursor.getColumnIndex(\"Size\"))));\n        return list;\n    }\n    return null;\n}\n<\/code><\/pre>\n<p><strong>Update part 5<\/strong><\/p>\n<p>as you have made the method to get all the data from the database now if you need to get the specific row you need to just changed the query <\/p>\n<pre><code>\/\/ get userlist\n    public List&lt;UserList&gt; getuserlistRow(String id) {\n        String selectQuery = \"SELECT firstname , lastname\"\n                + DATABASE_TABLE_NAME;\n        SQLiteDatabase db = this.getReadableDatabase();\n        Cursor cursor = db.rawQuery(\"SELECT * From YOUR_TABLE_NAME where id=\"'id'\"\", null);\n        List&lt;UserList&gt; userlist = new ArrayList&lt;UserList&gt;();\n        if (cursor.moveToFirst()) {\n            do {\n                UserList list = new UserList();\n                list.setId(Integer.parseInt(cursor.getString(0)));\n                list.setFirstname(cursor.getString(3));\n                list.setLastname(cursor.getString(4));\n                userlist.add(list);\n\n            } while (cursor.moveToNext());\n        }\n        return userlist;\n\n    }\n<\/code><\/pre>\n<blockquote>\n<p>now on button click , you can do this  ArrayList  myList =<br \/>\n  new ArrayList(getuserlistRow(id));<br \/>\n  Toast.makText(your_context,&#8221;&#8221;+myList.toString(),Toast.LENGTH_LONG).show():<\/p>\n<\/blockquote>\n<p><strong>Note<\/strong><\/p>\n<blockquote>\n<p>the above lines and shared code may have syntax error I have just given you the idea ,you can search the syntax on internet easily. <\/p>\n<\/blockquote>\n<p>so in this way you are getting all the the data in a complete record , this method is returning data in a array list of of my data type which is &#8220;Detail&#8221; in my case , you can cast into your data type. <\/p>\n<p>I hope this helps you in understanding how to do that. <\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">31<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved If i click on edit button particular row data should be fetch in listview? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] With out code I can not help you but I think you do not have the direction or road map . let me show you the road map so that you know how to achieve what you want to do : implement the click listener on list view. the click should be according to &#8230; <a title=\"[Solved] If i click on edit button particular row data should be fetch in listview?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/\" aria-label=\"More on [Solved] If i click on edit button particular row data should be fetch in listview?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[452],"class_list":["post-30165","post","type-post","status-publish","format-standard","hentry","category-solved","tag-android"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Solved] If i click on edit button particular row data should be fetch in listview? - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] If i click on edit button particular row data should be fetch in listview? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] With out code I can not help you but I think you do not have the direction or road map . let me show you the road map so that you know how to achieve what you want to do : implement the click listener on list view. the click should be according to ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-13T10:04:57+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\\\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] If i click on edit button particular row data should be fetch in listview?\",\"datePublished\":\"2023-01-13T10:04:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\\\/\"},\"wordCount\":633,\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"keywords\":[\"android\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\\\/\",\"name\":\"[Solved] If i click on edit button particular row data should be fetch in listview? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\"},\"datePublished\":\"2023-01-13T10:04:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] If i click on edit button particular row data should be fetch in listview?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\\\/\\\/jassweb.com\"],\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/author\\\/jaspritsinghghumangmail-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] If i click on edit button particular row data should be fetch in listview? - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] If i click on edit button particular row data should be fetch in listview? - JassWeb","og_description":"[ad_1] With out code I can not help you but I think you do not have the direction or road map . let me show you the road map so that you know how to achieve what you want to do : implement the click listener on list view. the click should be according to ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/","og_site_name":"JassWeb","article_published_time":"2023-01-13T10:04:57+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] If i click on edit button particular row data should be fetch in listview?","datePublished":"2023-01-13T10:04:57+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/"},"wordCount":633,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["android"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/","url":"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/","name":"[Solved] If i click on edit button particular row data should be fetch in listview? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2023-01-13T10:04:57+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-if-i-click-on-edit-button-particular-row-data-should-be-fetch-in-listview\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] If i click on edit button particular row data should be fetch in listview?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/30165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=30165"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/30165\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=30165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=30165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=30165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}