码迷,mamicode.com
首页 > 其他好文 > 详细

databinding

时间:2017-11-16 11:45:33      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:util   def   utf-8   padding   vertica   bind   www   visible   tab   

bind,graud 里面添加

dataBinding { enabled = true }
<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="viewModel" type="com.shire.mvvmdemo.viewModel.MainViewModel" /> </data> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activi


作者:希灵丶
链接:http://www.jianshu.com/p/981a2aa956b2
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="viewModel" type="com.shire.mvvmdemo.viewModel.MainViewModel" /> </data> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activi


作者:希灵丶
链接:http://www.jianshu.com/p/981a2aa956b2
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
<?xml version="1.0" encoding="utf-8"?>

<layout xmlns:android="http://schemas.android.com/apk/res/android">
  <data>
    <variable
        name="viewModel"
        type="com.shire.mvvmdemo.viewModel.MainViewModel"
        />
  </data>
  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activi


作者:希灵丶
链接:http://www.jianshu.com/p/981a2aa956b2
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

 

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
        binding.setViewModel(new MainViewModel(binding));
    }
}


作者:希灵丶
链接:http://www.jianshu.com/p/981a2aa956b2
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

 

public class MainViewModel implements onSearchListener { private ActivityMainBinding binding; private SearchModel searchModel = new SearchModel(); private Handler handler; public MainViewModel(ActivityMainBinding binding) { this.binding = binding; handler = new Handler(Looper.getMainLooper()); } public void search(View view) { binding.pbLoad.setVisibility(View.VISIBLE); searchModel.getIPaddressInfo(binding.etIp.getText().toString().trim(), this); } @Override public void onSuccess(final IPAddress ipAddress) { handler.post(new Runnable() { @Override public void run() { binding.pbLoad.setVisibility(View.GONE); binding.tvMsg.setText(ipAddress.toString()); } }); } @Override public void onError() { handler.post(new Runnable() { @Override public void run() { binding.pbLoad.setVisibility(View.GONE); binding.tvMsg.setText("查询失败"); } }); } }


作者:希灵丶
链接:http://www.jianshu.com/p/981a2aa956b2
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
public class MainViewModel implements onSearchListener {

  private ActivityMainBinding binding;
  private SearchModel searchModel = new SearchModel();
  private Handler handler;

  public MainViewModel(ActivityMainBinding binding) {
    this.binding = binding;
    handler = new Handler(Looper.getMainLooper());
  }

  public void search(View view) {
    binding.pbLoad.setVisibility(View.VISIBLE);
    searchModel.getIPaddressInfo(binding.etIp.getText().toString().trim(), this);
  }

  @Override public void onSuccess(final IPAddress ipAddress) {
    handler.post(new Runnable() {
      @Override public void run() {
        binding.pbLoad.setVisibility(View.GONE);
        binding.tvMsg.setText(ipAddress.toString());
      }
    });
  }

  @Override public void onError() {

    handler.post(new Runnable() {
      @Override public void run() {
        binding.pbLoad.setVisibility(View.GONE);
        binding.tvMsg.setText("查询失败");
      }
    });
  }
}


作者:希灵丶
链接:http://www.jianshu.com/p/981a2aa956b2
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

 

public class MainViewModel implements onSearchListener {

  private ActivityMainBinding binding;
  private SearchModel searchModel = new SearchModel();
  private Handler handler;

  public MainViewModel(ActivityMainBinding binding) {
    this.binding = binding;
    handler = new Handler(Looper.getMainLooper());
  }

  public void search(View view) {
    binding.pbLoad.setVisibility(View.VISIBLE);
    searchModel.getIPaddressInfo(binding.etIp.getText().toString().trim(), this);
  }

  @Override public void onSuccess(final IPAddress ipAddress) {
    handler.post(new Runnable() {
      @Override public void run() {
        binding.pbLoad.setVisibility(View.GONE);
        binding.tvMsg.setText(ipAddress.toString());
      }
    });
  }

  @Override public void onError() {

    handler.post(new Runnable() {
      @Override public void run() {
        binding.pbLoad.setVisibility(View.GONE);
        binding.tvMsg.setText("查询失败");
      }
    });
  }
}


作者:希灵丶
链接:http://www.jianshu.com/p/981a2aa956b2
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

 

 
<?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="viewModel" type="com.shire.mvvmdemo.viewModel.MainViewModel" /> </data> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activi


作者:希灵丶
链接:http://www.jianshu.com/p/981a2aa956b2
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

databinding

标签:util   def   utf-8   padding   vertica   bind   www   visible   tab   

原文地址:http://www.cnblogs.com/leshen/p/7842639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!