This post is going to save lot of your time from using the FindViewById. So I found this interesting article on Medium.com No more findviewById written by George Mount. and I thought why don't I write how it can be done in sample program . That would be much easier to understand isn't . So here it is.
And please read the article first from Medium.com first .
In this post I will demonstrate you , how to use dataBinding option in Android Studio, which will will eliminate the painful part of binding every view in xml with your Java. Your Android Studio must be version 1.5 and Higher.
1. Add the Following lines to your app Build.gradle file :
After adding this line to your app gradle file, the file should look something like this.
you can download the full working code from here
And please read the article first from Medium.com first .
In this post I will demonstrate you , how to use dataBinding option in Android Studio, which will will eliminate the painful part of binding every view in xml with your Java. Your Android Studio must be version 1.5 and Higher.
1. Add the Following lines to your app Build.gradle file :
android{ dataBinding.enabled = true; }
After adding this line to your app gradle file, the file should look something like this.
apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.0" dataBinding.enabled = true; defaultConfig { applicationId "com.hourglass.lingaraj.nofindviewbyid" minSdkVersion 9 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.0.0' compile 'com.android.support:recyclerview-v7:24.0.0' }
2. activity_main.xml:
This will have two button and one text view layout. On pressing the first , will display a toast message of text which is shown in the textview. The second button is an example for using Databinding with Recyclerview. So that will take you different activity , in which the recyclerview will display list of names.
<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.hourglass.lingaraj.nofindviewbyid.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_centerHorizontal="true" android:textSize="18sp" android:id="@+id/hello_textview" android:text="example no findview by id" android:layout_alignParentLeft="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Display Toast" android:id="@+id/display_toast" android:layout_below="@+id/hello_textview" android:layout_centerHorizontal="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Binding Example Recyclerview" android:id="@+id/recylerview_click" android:layout_below="@+id/display_toast" android:layout_centerHorizontal="true" /> </RelativeLayout> </layout>
4. MainActivity.java:
public class MainActivity extends AppCompatActivity { ActivityMainBinding activityMainBinding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); activityMainBinding = DataBindingUtil.setContentView(this,R.layout.activity_main); activityMainBinding.displayToast.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(getApplicationContext(),activityMainBinding.helloTextview.getText().toString(),Toast.LENGTH_SHORT).show(); } }); activityMainBinding.recylerviewClick.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplicationContext(),ActivityRecylerExample.class); startActivity(intent); } }); } }
5. DisplayNameListAdapter:
Code showing how to Databinding with Recyclerview.
Code showing how to Databinding with Recyclerview.
public class DisplayNameListAdapter extends RecyclerView.Adapter<DisplayNameListAdapter.ViewHolder> { private String TAG = "Recycler Adapter"; private Context mContext; private String[] names = {"John","Leo","Luke","mark"}; public DisplayNameListAdapter(Context context) { this.mContext = context; } public static class ViewHolder extends RecyclerView.ViewHolder { RecyclerviewlayoutsampleBinding binding; public ViewHolder(Context context,View view) { super(view); binding = DataBindingUtil.bind(view); } public RecyclerviewlayoutsampleBinding getBinding() { return binding; } } @Override public DisplayNameListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(this.mContext).inflate(R.layout.recyclerviewlayoutsample, parent, false); ViewHolder viewHolder = new ViewHolder(this.mContext,view); return viewHolder; } @Override public void onBindViewHolder(DisplayNameListAdapter.ViewHolder holder, int position) { // holder.getBinding().name.setText(this.names[position]); holder.getBinding().name.setText(this.names[position]); holder.getBinding().executePendingBindings(); Log.d(TAG,this.names[position]); } @Override public int getItemCount() { return this.names.length; } }
you can download the full working code from here
This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.Thank you for this blog. This for very interesting and useful.
ReplyDeleterpa Training in Chennai
rpa Training in bangalore
rpa Training in pune
blueprism Training in Chennai
blueprism Training in bangalore
blueprism Training in pune
iot-training-in-chennai
This looks absolutely perfect. All these tiny details are made with lot of background knowledge. I like it a lot.
ReplyDeleteData Science with Python training in chenni
Data Science training in chennai
Data science training in velachery
Data science training in tambaram
Data Science training in anna nagar
Data Science training in chennai
Data science training in Bangalore
This is a terrific article, and that I would really like additional info if you have got any. I’m fascinated with this subject and your post has been one among the simplest I actually have read.
ReplyDeleteBlueprism training in Pune
Blueprism training in Chennai
Great blog, keep posting and update more information.
ReplyDeleteSelenium Training in Chennai
Best Selenium Training Institute in Chennai
ios developer training in chennai
Digital Marketing Training in Chennai
.Net coaching centre in chennai
Best DOT NET Training institute in Chennai
asp.net training in chennai
Big Data Training in Chennai
I Got Job in my dream company with decent 12 Lacks Per Annum Salary, I have learned this world most demanding course out there in the current IT Market from the Data Science Course in Bangalore Providers who helped me a lot to achieve my dreams comes true. Really worth trying.
ReplyDeleteNice Blog!!. Thanks For Sharing..
ReplyDeleteHR and Payroll Software
Best HR Solution
Attendance Software
Human Resource Management
HR Payroll Processing
Leave management Softwar.Automation Anywhere Training in Bangalore
thank you for supporting by posting this info
ReplyDeleteAngularJS Training in Chennai | AngularJS Training in Anna Nagar | AngularJS Training in OMR | AngularJS Training in Porur | AngularJS Training in Tambaram | AngularJS Training in Velachery
Thanks you for sharing this unique useful information content with us. Really awesome work. keep
ReplyDeleteon blogging
Salesforce Training | Online Course | Certification in chennai | Salesforce Training | Online Course | Certification in bangalore | Salesforce Training | Online Course | Certification in hyderabad | Salesforce Training | Online Course | Certification in pune
"Hi! Thank you for the share this information. This is very useful information for online blog review readers. Keep it up ..
ReplyDeleteDigital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery
"
Hi,Great information.Thanks for sharing.I always read your blog and get lot of useful information.
ReplyDeletehadoop training in chennai
hadoop training in porur
salesforce training in chennai
salesforce training in porur
c and c plus plus course in chennai
c and c plus plus course in porur
machine learning training in chennai
machine learning training in porur
I really appreciate this post. I’ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thanks again!
ReplyDeleteweb designing training in chennai
web designing training in tambaram
digital marketing training in chennai
digital marketing training in tambaram
rpa training in chennai
rpa training in tambaram
tally training in chennai
tally training in tambaram
After reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
ReplyDeletejava training in chennai
java training in annanagar
aws training in chennai
aws training in annanagar
python training in chennai
python training in annanagar
selenium training in chennai
selenium training in annanagar
This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me..
ReplyDeleteangular js training in chennai
angular js training in omr
full stack training in chennai
full stack training in omr
php training in chennai
php training in omr
photoshop training in chennai
photoshop training in omr
After seeing your article I want to say that the presentation is very good and also a well-written article with some very good information which is very useful for the readers....thanks for sharing it and do share more posts like this.
ReplyDeleteAngular js Training in Chennai
Angular js Training in Velachery
Angular js Training in Tambaram
Angular js Training in Porur
Angular js Training in Omr
Angular js Training in Annanagar
Your article very impressive. Content is really easy to understand. Appreciate your efforts on this. Keep blogging
ReplyDeleteSelenium Training in Chennai
Selenium Training in Velachery
Selenium Training in Tambaram
Selenium Training in Porur
Selenium Training in Omr
Selenium Training in Annanagar
Awesome post. Really you are shared very informative concept... Thank you for sharing. Keep on updating...
ReplyDeleteamazon web services aws training in chennai
microsoft azure training in chennai
workday training in chennai
android-training-in chennai
ios training in chennai
I really appreciate this post. I’ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thanks again!
ReplyDeleteIELTS Coaching in chennai
German Classes in Chennai
GRE Coaching Classes in Chennai
TOEFL Coaching in Chennai
Spoken english classes in chennai | Communication training
Python Training Institute in Chennai | Infycle technologies:
ReplyDeleteIf you learn Python to take your career to the next level with Infycle Technologies. Infycle Technologies is the best Python training Institute. It provides big data certification courses in Chennai and conducts 200% practical training with professional trainers in this field. In addition to the training, we will also arrange internship interviews for the trainees, so that the trainees can effortlessly add to their careers. Among them, a 100% resettlement guarantee will be obtained here. For the best competition, please call Infycle Technologies 7502633633 and get a free demo to learn more.
Best training center in Chennai
Description:
ReplyDeleteInfycle Technologies is the best software training center in Chennai, providing amazing Data Science training in Chennai which will be realistic and taught by industry experts. Aside from practical training preparation, mock interviews will be arranged for students so that they can confidently face the interviews. All of this will be packed up by full placement assurance with the best salary package from top companies. For having a free demo session, call 7502633633.
Best software training in chennai
perde modelleri
ReplyDeletesms onay
mobil ödeme bozdurma
nft nasil alınır
Ankara Evden Eve Nakliyat
TRAFİK SİGORTASI
dedektör
web sitesi kurma
aşk kitapları
özel ambulans
ReplyDeleteuc satın al
lisans satın al
yurtdışı kargo
en son çıkan perde modelleri
en son çıkan perde modelleri
nft nasıl alınır
minecraft premium
Good text Write good content success. Thank you
ReplyDeletetipobet
kibris bahis siteleri
slot siteleri
kralbet
mobil ödeme bahis
poker siteleri
betmatik
betpark
kocaeli
ReplyDeletekonya
kuşadası
kütahya
malatya
LCL1
bitlis
ReplyDeleteedirne
hatay
ağrı
urfa
SNYJG
https://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
5XRS2J
ReplyDeleteشركة انشاء مسابح بجدة
انشاء مسابح