这是我活动中onCreate方法的实现。我需要动态创建选项卡。为了简单起见,我制作了2个选项卡。
public class ActivityProductList extends AppCompatActivity {
private android.support.v7.widget.SearchView searchView = null;
private RecyclerView recyclerView;
MyAdapter adapter;
List<ParentListItem> parentListItems = new ArrayList<>();
List<ParentListItem> originalProductList = new ArrayList<>();
String query = null;
int categoryId = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_products_final);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("PRODUCTS");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
//setupViewPager(viewPager);
//tabLayout.setupWithViewPager(viewPager);
//viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
searchView = (android.support.v7.widget.SearchView) findViewById(R.id.searchView);
searchView.setIconified(false);
searchView.onActionViewExpanded();
searchView.clearFocus();
searchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (adapter != null)
filterData(query);
return false;
}
@Override
public boolean onQueryTextChange(String query) {
if (adapter != null)
filterData(query);
return false;
}
});
}
}
我希望在点击选项卡时更改同一活动中的EditText
的值。
如何在活动中获取选项卡点击事件?
OnTabSelectedListener
怎么样? - Mike M.