Search in sources :

Example 1 with BaseAdapter

use of xyz.zpayh.adapter.BaseAdapter in project SherlockAdapter by EvilBT.

the class MainActivity method initView.

private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mRecyclerView = (RecyclerView) findViewById(R.id.list);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    final BaseAdapter<String> adapter = new BaseAdapter<String>() {

        @Override
        public int getLayoutRes(int index) {
            return R.layout.item_list;
        }

        @Override
        public void convert(BaseViewHolder holder, String data, int index) {
            holder.setText(R.id.tv_act_title, data);
        }

        @Override
        public void bind(BaseViewHolder holder, int layoutRes) {
            holder.setClickable(R.id.app_root, true);
        }
    };
    adapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(@NonNull View view, int adapterPosition) {
            String action = adapter.getData(adapterPosition);
            Intent intent = new Intent();
            intent.setAction(action);
            startActivity(intent);
        }
    });
    mRecyclerView.setAdapter(adapter);
    String[] list = getResources().getStringArray(R.array.activity_title);
    final List<String> data = new ArrayList<>(list.length);
    for (String s : list) {
        data.add(s);
    }
    adapter.setData(data);
}
Also used : BaseViewHolder(xyz.zpayh.adapter.BaseViewHolder) OnItemClickListener(xyz.zpayh.adapter.OnItemClickListener) ArrayList(java.util.ArrayList) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) BaseAdapter(xyz.zpayh.adapter.BaseAdapter) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Intent (android.content.Intent)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 ArrayList (java.util.ArrayList)1 BaseAdapter (xyz.zpayh.adapter.BaseAdapter)1 BaseViewHolder (xyz.zpayh.adapter.BaseViewHolder)1 OnItemClickListener (xyz.zpayh.adapter.OnItemClickListener)1