What I need unless my tablet is connected to a server I cant have the tabs being changed. I have a tab host that is all run off of the same java file. I figure all I need to do is have some sort of a test in the file to say unless boolean is true dont let the code change the tab. However I dont know how to do this? If you need to see any of my code just leave that in the comment box. Thanks for all your help !
Well I guess you can try disabling/enabling clicks on the tabs by calling:
myTabHost.getTabWidget().setClickable(isConnectedToServer);
But I'm not sure that's good UX, how about letting your users change tabs, but if the content can't be reached displaying a message inside the main view of the tab "server unreachable, check your internet connection" or something like that.
UPDATE:
Try this instead (for each of your tabs):
myTabHost.getTabWidget().getChildTabViewAt(0).setEnabled(false);
myTabHost.getTabWidget().getChildTabViewAt(1).setEnabled(false);
myTabHost.getTabWidget().getChildTabViewAt(2).setEnabled(false);
ANOTHER UPDATE:
public class MyActivity extends Activity {
private TabWidget mTabWidget = null;
protected void onCreate(Bundle savedInstanceState) {
...
mTabWidget = myTabHost.getTabWidget();
...
}
protected void refreshTabs(boolean isConnected) {
mTabWidget.getChildTabViewAt(0).setEnabled(isConnected);
mTabWidget.getChildTabViewAt(1).setEnabled(isConnected);
mTabWidget.getChildTabViewAt(2).setEnabled(isConnected);
}
Now you can call refreshTabs whenever you want in your code to make them enabled/disabled.
Related
I imagine someone has had this question before, I just don't quite know what the right keywords are to find the answer? I am making an android app with an activity that includes tabs using TabLayout. Nothing fancy, just really standard stuff. In fact, so far I've done literally nothing but make a completely new application with a single tabbed activity using the auto-generated code from Android Studio. Everything works fine, but there is one feature I cannot figure out how to turn off -- when I long click on any tab, a little rectangular alt text or something with the title of the tab pops up on screen just above the tab. It's not the end of the world if I can't eliminate it, I just find it to be irritating and incompatible with the overall desired feel of my app given that it's literally just duplicating the tab title. I can't find any code that is causing this to appear, so I don't know how to delete it. The picture below shows what I'm talking about circled in red.
If anyone needs me to post code to help answer, I can... but you can also just make a new tabbed activity in a throwaway application in Android Studio and get exactly the same boilerplate code I have.
Edit: I added the term "tooltip" to the title so others can find the relevant thread more easily if they have the same problem.
Kudos to Mike M. for the answer, shown in comments above. I implemented it successfully, so if anyone comes back here looking for the answer, here's the successful java code, which is placed in the onCreate() method of the activity containing the tabLayout:
// turn off that tooltip text thing immediately on activity creation
for (int i=0; i<tabs.getTabCount(); i++) {
TooltipCompat.setTooltipText(Objects.requireNonNull(tabs.getTabAt(i)).view, null);
}
tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
int tabPosition = tab.getPosition(); // syntactic sugar
viewPager2.setCurrentItem(tabPosition, true);
// Repeat of the code above -- tooltips reset themselves after any tab relayout, so I
// have to constantly keep turning them off again.
for (int i=0; i<tabs.getTabCount(); i++) {
TooltipCompat.setTooltipText(Objects.requireNonNull(tabs.getTabAt(i)).view, null);
}
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
I’ve been making android apps for like 4-5 days now. So i’m wondering if you know how I can make a web app? I have been looking through many tutorials, but none shows directly how I can make an app that displays the content from a website, and that I can decide what I want and don’t want to display. So I really just want to customize a website into an app and make my own layout. I know how the WebView and WebContent works and all that stuff, but I don’t know how I can do what I described here.
So what do I need to learn and know to make an app like that?
You can do it by fill your xml layout with EdidText for the url and Buttons for Go, back, forward and so on, finally you need webview in this xml layout.
for the java code you can check the below sample.
public class SimpleBrowser extends Activity implements OnClickListener {
WebView myBrowser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simplebrowser);
//here the code for initialize and set yourwebView Settings.
myBrowser= (WebView) findViewById(R.id.wvBrowser);
//the below line to enable javascript if you want that
myBrowser.getSettings().setJavaScriptEnabled(true);
//here another settings could be enabled for you your webview
myBrowser.getSettings().setLoadWithOverviewMode(true);
myBrowser.getSettings().setUseWideViewPort(true);
try {
//here the default web page
ourBrow.loadUrl("http://www.google.com");
}catch (Exception e){
e.printStackTrace();
}
}
}
and for sure you need to implements your buttons using onClicklistener to be suitable for your idea.
https://www.youtube.com/watch?v=lkadcYQ6SuY&index=89&list=PL2F07DBCDCC01493A
https://www.youtube.com/watch?v=PQ94MmEg0Qw&index=90&list=PL2F07DBCDCC01493A
I already asked this question, but got answers that don't work and it counted as "Answered". Maybe someone knows how to design button in Eclipse for an Android app, so it takes you to a website ?Let's say this website.Thanks a lot.
Say u wanna go to google.com
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onOpenWebBrowser(View v)
{
Intent webPageIntent = new Intent(Intent.ACTION_VIEW);
webPageIntent.setData(Uri.parse("https://www.google.co.in/"));
try {
startActivity(webPageIntent);
} catch (ActivityNotFoundException ex) {
}
}
}
Make sure u add uses internet permission to the manifest!
you can refer the following to get an idea ,
see this vogella from there, you can get idea how to create android app which has a Button
http://www.vogella.de/articles/Android/article.html
and then create WebView in xml and map it in java, as
http://developer.android.com/resources/tutorials/views/hello-webview.html
and For mor info refer android people.com
http://www.androidpeople.com/
http://developer.android.com/resources/samples/index.html
and also read my blog to know about android basics
http://sankarganesh-info-exchange.blogspot.com/p/corridor-your-foremost-footstep-in.html
You would need to set up an OnClickListener and tie it to your button. In the Listener's onClick method, you would load the specified URL into the WebView, which, based on your comments, it sounds like you've got that part figured out.
I am making an app that has a scrolling screen like the homescreen style. I have implemented this solution:
Android Homescreen
It works great but I also want there to be buttons on each page that you can click to go to the next page but I just can't figure out how to do it! can someone help? I've been staring at this code for days now!
Thanks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
UPDATE - HELP
I really don't understand how to get around the problem of calling the SetToScreen from the other activity, Can anyone help as if I try I do keep getting Static call errors.
Look at
public void setToScreen(int whichScreen) {}
Use this function to set to a screen on a click.
you should extend Draggablespace by adding a function to get the current space like:
public int getCurrentScreen() {
return this.mCurrentScreen;
}
then you can write your own functions in your activity like
public void nextScreen() {
draggableSpace.setToScreen(draggableSpace.getCurrentScreen() + 1));
}
The same for previous screen.
Now you only need to check if there is an additional screen waiting if you are going forward or backward.
(Of course draggableSpace is your object of the class draggablespace...not a static call!)
I am playing with an ap that has 2 webviews set up within a tabhost/tabwidget layout, my problem is that i don't know how to make them navigate back through page history, at least for both of them. I ca do it for the first webview (webview1) but i don't know how to do it for the second one in my second tab.
I know this question is ancient but you might still be stuck on it, or someone else might be. Use the code below, it works for me using tabHost. webView1 and webView2 being your two webviews.
Add it above the onCreate bundle.
public void onBackPressed(){
if (webView1.isFocused() && webView1.canGoBack()) {
webView1.goBack();
}
else {
//Add something you want to do, or leave blank to do nothing.
}
if (webView2.isFocused() && webView2.canGoBack()) {
webView2.goBack();
}
else {
//Add something you want to do, or leave blank to do nothing.
}
}