Created
November 11, 2015 09:37
-
-
Save umetsu/400255ac886b4bef9b8b to your computer and use it in GitHub Desktop.
Android DataBinding - Listener bind sample
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" | |
xmlns:app="http://schemas.android.com/apk/res-auto"> | |
<data> | |
<variable | |
name="activity" | |
type="net.prunusmume.databindingsample.ListenerBindActivity" /> | |
</data> | |
<RelativeLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_centerInParent="true" | |
android:text="タップしてね!" | |
app:onClickListener="@{activity.buttonClickListener}" /> | |
</RelativeLayout> | |
</layout> |
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
package net.prunusmume.databindingsample; | |
import android.databinding.DataBindingUtil; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Toast; | |
import net.prunusmume.databindingsample.databinding.ActivityListenerBindBinding; | |
public class ListenerBindActivity extends AppCompatActivity { | |
private final View.OnClickListener mButtonClickListener = new View.OnClickListener() { | |
@Override | |
public void onClick(final View v) { | |
Toast.makeText(ListenerBindActivity.this, "タップされたよ", Toast.LENGTH_SHORT).show(); | |
} | |
}; | |
@Override | |
protected void onCreate(final Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
final ActivityListenerBindBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_listener_bind); | |
binding.setActivity(this); | |
} | |
public View.OnClickListener getButtonClickListener() { | |
return mButtonClickListener; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment