zoukankan      html  css  js  c++  java
  • databinding

    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
    
    
    
    
    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));
        }
    }
    
    
    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("查询失败");
          }
        });
      }
    }
    
    
     
    <?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
    來源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    golang 识别redis key在哪个codis的slot上
    QAT SSL加速卡安装及使用
    dereferencing pointer to incomplete type错误的解决办法
    golang topN算法
    golang日志框架zap简洁配置
    golang 读取文件
    Django学习目录
    go练习:循环与函数
    全站搜索实战应用(Lucene.Net+盘古分词)
    (原创)将Datatable数据按照Excel模板格式导出
  • 原文地址:https://www.cnblogs.com/leshen/p/7842639.html
Copyright © 2011-2022 走看看