Simulate tabhost click - java

At the moment I am using this to call the TabHost activity to change tabs:
public void switchTab(int index){
MintTrack ParentActivity;
ParentActivity = (MintTrack) this.getParent();
ParentActivity.getTabHost().setCurrentTab(3);
}
This works well, however, the WebView item in tab "3" remains unfocused, until i touch it...
I need to programatically simulate a click on tab 3 then, as clicking the tab automatically places the focus on the webview... Any ideas?

Try this:
getTabHost().getTabWidget().getChildAt(3).performClick();

I'm not sure if it will work, but you can try requesting focus for the child at index 3.
ParentActivity.getTabHost().getTabWidget().getChildAt(3).requestFocus();

Related

How to use onBackPressed in an activity that swipes the screen with another activity?

I've a little problem. I've two activities (GalleryActivity and GalleryVideoActivity) and after swiping between them, i would to come back to the first activity (GalleryActivity) pressing just one time on back button because i've to press back button as many times as i swipped. Is it possible? Thanks in advance to everyone!
So if i understand your issue is that you are moving between activities and everytime you move they create new instances so as a solution to suggest is as following ,
in your manifest file , in activity section add launchMode="SingleInstance" , as this would create only one instance of that activity .
This is an example
<activity
android:name=".ui.apppassword.PasswordRestoreActivity"
android:screenOrientation="portrait"
android:launchMode="singleInstance"/>
In GalleryVideoActivity override onBackpress method and navigate back to the GalleryActivity by putting simple intent.
Here is what you need to add to GalleryVideoActivity in order to implement onBackPressed as Mike stated:
#Override
public void onBackPressed() {
Intent toGalleryActivity = new Intent(this, GalleryActivity.class);
startActivity(toGalleryActivity);
}
This starts GalleryActivity everytime the back button is pressed in GalleryVideoActivity.

JavaFx Button enabler in listview

I have 4 simple buttons that interact with a listview. If you click a certain button you can go one down, one up, to the start and to the end of the listview. So each button has a different onAction method:
(Buttons: previous, next, end, start)
public void toNext(){
list.getSelectionModel().selectNext();
}
public void toPrevious(){
list.getSelectionModel().selectPrevious();
...
But now I want to disable the buttons if they can't go to the start, end, up or down. I tried to do the following by adding this code to the method toPrevious (example):
previous.setDisable(list.getSelectionModel().getSelectedIndex() == 0)
This code does disable the button but it won't enable it when you can go to the previous string in the listview. Does anyone has a simple solution for this?
You can use a binding:
previous.disableProperty().bind(
list.getSelectionModel().selectedIndexProperty().isEqualTo(0));
next.disableProperty().bind(
list.getSelectionModel().selectedIndexProperty().isEqualTo(
Bindings.size(list.getItems()).subtract(1)));

Disabling Android Button depending on Permissions

I have an android app that uses the permission "CALL_PHONE". This simple app would just contain a button that would use the call intent to call a specific number. I would like to install this app on both tablets and phone but when it is installed on the tablet, I would like the button to be disabled during runtime so errors wouldn't show when the user tries to call using the tablet without a call function.
At the moment, I am using the setEnabled() and setClickable() method in my MainActivity.java and setting it to false when the user clicks on the button the first time. My question is whether the button can be disabled and the text changed during runtime or when the app is first opened (in a tablet) so the user wouldn't have to click the button first for it to show that the "call" button should be disabled and unclickable?
Refer to this
That will help you in identifying that your application is running on tablet. Now as for disabling your button, I would suggest something like this:
onCreate()
{
setContentView(R.layout.main);
boolean isTablet = checkDevice();
callBtn = (Button) findViewById(R.id.call);
if (isTablet)
{
callBtn.setEnabled(false);
callBtn.setText("Not allowed to make a call");
}
callBtn.setOnClickListener( new onClickListener(){
//Make a call
});
}
public boolean isTablet()
{
//Code for identifying. Return true if application is running on tablet
//return false otherwise
}
So you won't have to wait for user's click on Call button to disable it in tablet.
Hope that helps.
Use button.setEnabled(false); to make visible but user cant click and
button.setVisibility(View.GONE); to make button invisible.and button.setText("YOUR_NEW_TEXT"); to change the button text runtime
And this is not depend on the size of the screen.
Is this you wanted?? OR be more specific with your queston.
... the text changed during runtime?
You can use the setText(); method.
About the other part of your question, you need first to define "What is a tablet?". Is it a 7", 8", 10" screen? Is it a mdpi, hdpi, xhdpi screen? Is it a device which is able to do phone calls? What is a tablet for you or your project? Depending on your answer, you can filter your code (or xml in folders) to make them work the way you want.

TabHost to launch external browser when clicked

I have some tabs in my app and I want the last tab to launch google in the default system browser. I thought this would work:
Uri uri = Uri.parse("http://www.google.com/");
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Google", res.getDrawable(R.drawable.google)).setContent(new Intent(Intent.ACTION_VIEW, uri)));
But it results in a force close error. Any tips on getting this working?
EDIT
I solved this. Basically what I do is add an onClick event handler to capture when the tab is clicked in the first place (only this tab in question) and then from within that I prevent the default action by returning true (for handled) after launching a new Intent in the regular fashion.
You can start an Activity from Tab Host(that you have mention as last Tab Host).Then from that activity you can launch external Browser.As i think its not possible to launch default activity from TabHost.
Edited
I have checked it.It give ActivityNotFound Exception.Conclusion is that TabHost look for the activity that is registered in Android manifest.If you want to achieve it then go with my first suggestion

Show Tab Widget on each and every Activity

Using Java, how can I show a Tab Widget on each and every Activity, even if that Activity is a subActivity of FirstActivity? If possible, please provide me with some code or examples.
Use THis to start the new Activity
View view = getLocalActivityManager().startActivity("tab1", new Intent(this,tab1.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
setContentView(view);
Create Another GroupActivity and putExtra info along with your intent so when it gets it ,the group activity can check what tab should be opened.Use My code to open the new Tab.

Categories

Resources