D
D
Dmitry Chilikin2017-09-04 17:11:09
Java
Dmitry Chilikin, 2017-09-04 17:11:09

How to update tab content in TabHost?

Good afternoon!
How to update tab contents in TabHost by clicking on titles? I have already tracked the click on the tab and I can "hang" the event and define the tab tag, but I don't understand how to update its content. tabHost.removeViewAt(0) - removes tab 0, and you need to create it again and "hang" the event, which is not entirely correct. When switching between tabs, the content is updated thanks to the Intent.FLAG_ACTIVITY_CLEAR_TOP flag.
Code example:

int numberOfTabs = tabHost.getTabWidget().getChildCount();
        for(int n=0; n<numberOfTabs; n++) {
            tabHost.getTabWidget().getChildAt(n).setOnTouchListener(new View.OnTouchListener() {
                @SuppressLint("LongLogTag")
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_UP) {
                        String currentSelectedTag = tabHost.getCurrentTabTag();
                        for(int l=0; l<tabHost.getTabWidget().getChildCount(); l++) {
                            View f = tabHost.getTabWidget().getChildTabViewAt(l);
                            TextView tv1 = (TextView) f.findViewById(R.id.textView1);
                            tv1.setTypeface(Typeface.DEFAULT);
                            tv1.setTextColor(Color.parseColor("#bdbdbd"));
                            tv1.setBackgroundResource(android.R.color.transparent);
                        }
                        TextView tv = (TextView) v.findViewById(R.id.textView1);
                        tv.setTypeface(Typeface.DEFAULT_BOLD);
                        tv.setTextColor(Color.parseColor("#ffffff"));
                        tv.setBackgroundResource(R.drawable.edittext_bg);
                        Log.d("@@@@@@@@@@ onClick", "onClick tab "+v.getTag());// v.getTag() - тег вьюхи текущей вкладки
// где-то здесь нужно обновить текущий intent
                    }
                    return false;
                }
            });
        }

Already rummaged through the whole stack, I can not find anything like it. What are the considerations?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2017-09-04
@zagayevskiy

There are considerations. Don't use ancient mammoth crap like TabHost.
By the way, instead of Color.parseColor("#ffffff") you can write 0xffffff. And it is better to take out such things in styles/constants at least.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question