I am trying to place a button in the TabWidget, meaning that I want to see all the tabs and the most right one will be a button.
I couldn’t do it with the xml (and it will be helpful if someone would tell me how) so I’ve added the button by code.
The problem is that the button is not clicked, I hear the click sound from the device but nothing happens, I don’t see that the OnClickListener is called.
Can you please look at the code and tell me what I am doing wrong?
This code is at the onCreate() of my activity.
TabWidget tabWidget = (TabWidget)findViewById(android.R.id.tabs);
Button button = new Button(this);
button.setBackgroundResource(R.drawable.settings);
button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
button.setClickable(true);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LogWrapper.d(TAG, "************************************");
startActivity(new Intent(MyActivity.this, SettingsActivity.class));
}
});
tabWidget.addView(button);
I have a solution, I don’t know if it’s the best one, but it’s something to offer.
I’ve built xml file with a single button in it, inflate it and add it to the TabWidget, this seems to work.
settings_button.xml
MyActivity.java
Anyway, this is my solution offer. After checking it, it doesn’t look good a button in the TabWidget. I’ll think what to do with it.