This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
private User user; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main); | |
user = new User(); | |
user.setName("Prakash"); | |
user.setEmail("praks@email.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyHandlers { | |
public void btnClick(View view, User user) { | |
Toast.makeText(view.getContext(),"Name: "+user.getName() , Toast.LENGTH_LONG).show(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android"> | |
<data> | |
<variable | |
name="user" | |
type="com.tuts.prakash.databinding.model.User" /> | |
<variable name="handler" | |
type="com.tuts.prakash.databinding.handlers.MyHandlers"/> | |
</data> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User { | |
private String name; | |
private String email; | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
dataBinding { | |
enabled = true | |
} | |
compileSdkVersion 27 | |
. | |
. | |
. | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<TextView | |
android:text="@{user.userName}" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TextView textView = findViewById(R.id.text); | |
textView.setText(user.getUserName()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mShowVideoButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
if (mRewardedVideoAd.isLoaded()) { | |
mRewardedVideoAd.show(); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Load Rewarded Ad | |
mRewardedVideoAd.loadAd(getString(R.string.ad_unit_id), new AdRequest.Builder().build()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mRewardedVideoAd.setRewardedVideoAdListener(new RewardedVideoAdListener() { | |
@Override | |
public void onRewarded(RewardItem rewardItem) { | |
Toast.makeText(getBaseContext(), "You get reward of : "+rewardItem.getAmount(), Toast.LENGTH_SHORT).show(); | |
} | |
@Override | |
public void onRewardedVideoAdLoaded() { | |
Toast.makeText(getBaseContext(), "Ad loaded.", Toast.LENGTH_SHORT).show(); | |
} |
NewerOlder