官术网_书友最值得收藏!

  • Android Wear Projects
  • Ashok Kumar S
  • 259字
  • 2021-07-15 17:17:58

Working on activities and driving the project towards completion 

In MainActivity.java, we will have control over the classes that we have worked on so far. Let's get started on implementing all the necessary code and methods.

When we extend the Wear project activity to WearableActivity, we shall include the following code in the manifest <application ></application> tag scope:
<uses-library android:name="com.google.android.wearable" android:required="false" />. When we declare android: required="false" any feature that Android has control on will be disabled. In the context of Wear applications, when you need to extend your activity with WearableActivity, we need to set it to false.

Now, in MainActivity.java, let's add the basic variable instances necessary for the project. Add the following code globally in the MainActivity.java class scope:

private static final String TAG = "MainActivity";
private static final int REQUEST_CODE = 1001;
private RecyclerViewAdapter mAdapter;
private List<Note> myDataSet = new ArrayList<>();

Next, write a method for configuring the UI component. Let's call this method ConfigureUI(). In this method, we shall handle the click event. When a user clicks on the RecyclerView list item, it should take the user to the delete activity screen:  

private void configureUI() {
    WearableRecyclerView recyclerView = (WearableRecyclerView) 
    findViewById(R.id.wearable_recycler_view);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager mLayoutManager = new 
    LinearLayoutManager(this);
    recyclerView.setLayoutManager(mLayoutManager);

    mAdapter = new RecyclerViewAdapter();
    mAdapter.setListNote(myDataSet);
    mAdapter.setListener(this);
    recyclerView.setAdapter(mAdapter);

    EditText editText = (EditText) findViewById(R.id.edit_text);

    editText.setOnEditorActionListener(new 
    TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int 
        action, KeyEvent keyEvent) {
            if (action == EditorInfo.IME_ACTION_SEND) {
                String text = textView.getText().toString();
                if (!TextUtils.isEmpty(text)) {
                 //Todo add the on editText click handlers   
                 
                 return true;
                }
            }
            return false;
        }
    });
}
主站蜘蛛池模板: 沽源县| 克山县| 宜兰县| 黎平县| 曲麻莱县| 吐鲁番市| 沧源| 汕尾市| 武隆县| 商水县| 台前县| 洪湖市| 铜山县| 平凉市| 重庆市| 商丘市| 元江| 祁门县| 永平县| 彰化县| 伊吾县| 十堰市| 米易县| 中西区| 包头市| 淄博市| 博爱县| 金沙县| 齐齐哈尔市| 泽库县| 志丹县| 中西区| 二手房| 阿克苏市| 临夏市| 兴安县| 沈丘县| 海门市| 彰化市| 浏阳市| 马鞍山市|