{"id":13839,"date":"2020-02-19T13:36:56","date_gmt":"2020-02-19T13:36:56","guid":{"rendered":"https:\/\/ittutorial.org\/?p=13839"},"modified":"2020-02-19T13:36:56","modified_gmt":"2020-02-19T13:36:56","slug":"android-programming-15-custom-adapter","status":"publish","type":"post","link":"https:\/\/ittutorial.org\/android-programming-15-custom-adapter\/","title":{"rendered":"Android Programming -15 Custom Adapter"},"content":{"rendered":"<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">Hi guys in this tutorial we will continue the custom adapter.<\/p>\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">In my previous article, we started to customize of the listview. First of all, I recommend you to read it. You can read it <a href=\"https:\/\/ittutorial.org\/android-programming-14-custom-listview-2\/\">here<\/a>.<\/p>\n<pre>package com.example.teka.icim_rahat.adapters;\r\n\r\nimport android.content.Context;\r\nimport android.support.annotation.LayoutRes;\r\nimport android.support.annotation.NonNull;\r\nimport android.support.annotation.Nullable;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.widget.ArrayAdapter;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\nimport android.widget.TextView;\r\n\r\nimport com.example.teka.icim_rahat.R;\r\nimport com.example.teka.icim_rahat.models.icirahat_class;\r\n\r\nimport java.io.IOException;\r\nimport java.util.ArrayList;\r\n\r\n\/**\r\n\u00a0* Created by teka on 25.7.2017.\r\n\u00a0*\/\r\n\r\npublic class kullanici_adpter extends ArrayAdapter&lt;icirahat_class&gt; {\r\n\r\npublic kullanici_adpter(@NonNull Context context, @LayoutRes int resource, @NonNull ArrayList&lt;icirahat_class&gt; objects) throws IOException {\r\n\r\nsuper(context, resource, objects);}\r\n\r\nint sayac=0;\r\n\r\n@NonNull\r\n\u00a0\u00a0\u00a0 @Override\r\n\r\npublic View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {\r\n\r\nView v = convertView;\r\n\r\nif (v == null) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 LayoutInflater vi;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 vi = LayoutInflater.from(getContext());\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 v = vi.inflate(R.layout.icim_rahat_class, null);}\r\n\r\nicirahat_class hs = getItem(position);\r\n\r\nif (hs != null) {\r\n\r\nfinal ImageView txt = (ImageView) v.findViewById(R.id.txt);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 TextView yorum = (TextView) v.findViewById(R.id.yorum);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 final Button like = (Button) v.findViewById(R.id.like);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 txt.setImageResource(R.drawable.res);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 yorum.setText(\"cocuklarrrr\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 like.setOnClickListener(new View.OnClickListener() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Override\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public void onClick(View v) {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 sayac++;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (sayac%2==1){\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 like.setBackgroundResource(R.drawable.like);}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 else {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 like.setBackgroundResource(R.drawable.like_white);}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\r\n});}\r\nreturn v;\r\n\u00a0\u00a0\u00a0 }\r\n}<\/pre>\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">If we examine our code.<\/p>\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">we extend our adapter class from Arrayadaper class. We create the type of ArrayAdapter from the model we created in the previous lesson. Then we define the construction method of the adapter. When defining this method, we determine what parameters we need to create during create.<\/p>\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">We encode what we want to make our adapter into getView method.All the operations we will do on the components we add to the layout file we created for the views of the Listview item tags are also encoded for the adapter class.<\/p>\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">\n<p style=\"margin: 0in;font-family: Calibri;font-size: 11.0pt\">For example, in our code, we change the text of textview and set an image in imageview with a drawable folder. Activate the click feature of the Like button, we change the background of the button according to the number of clicks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi guys in this tutorial we will continue the custom adapter. In my previous article, we started to customize of the listview. First of all, I recommend you to read it. You can read it here. package com.example.teka.icim_rahat.adapters; import android.content.Context; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import &hellip;<\/p>\n","protected":false},"author":44,"featured_media":8094,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-13839","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-android"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/04\/featured-860x280.png","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/13839","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/comments?post=13839"}],"version-history":[{"count":1,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/13839\/revisions"}],"predecessor-version":[{"id":13840,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/13839\/revisions\/13840"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media\/8094"}],"wp:attachment":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media?parent=13839"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/categories?post=13839"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/tags?post=13839"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}