I am using the code from this post to put a loading icon in the title bar of my Android App:
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.your_layout);
}
The code:
activity.setProgressBarIndeterminateVisibility(true);
is called in an AsyncTask. If the user navigates to a new activity, the icon is not longer present in the title bar since the icon was set for the first activity only.
Is there a way to have the icon show on all activities? Thanks in advance.
You can create super activity (i.e. Base Activity), include the below line in this super activity:
activity.setProgressBarIndeterminateVisibility(true);
And extends this activity to all the child activities.
Related
When I first ran the sample HelloWorld app, it displays the hello world text on the emulator. I decided then to delete that and make a button. What I wanted is that when I click the button, it will show a text "This is the second activity". I made another XML file and another class to handle the second activity to display the text. But when I ran again, I cannot see the changes on the UI for the emulator. The text "This is the second activity" does not show after I clicked the button. I saved everything. How would I automatically update the UI of the emulator after some of the changes made on the design? I am new to android development. Please help me. Btw I cannot post images so it requires 10 reputation that's why I used online image viewing. Sorry for that.
Here is my Graphical layout on eclipse: activity_main.xml
http://s16.postimg.org/wusm4qrp1/image.png
second.xml
http://s29.postimg.org/qft17p5on/image.png
Running the emulator:
http://s28.postimg.org/f9dn32ku5/image.png
After clicking the button (in which case the text I edit does not show):
http://s16.postimg.org/75r62dodx/image.png
Because you didn't post your code, I'll try to explain it from the beginning.
I don't know if you can do it in an other way, but the following answer assumes we aim the good programming practice.
Both of the activities have their distinct layouts set in the following way, right?
public class MyFirstActivity extends Activity{
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
...
public class MySecondActivity extends Activity{
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
...
Then, in your first activity, define onClickListener of your button
...
setContentView(R.layout.activity_first);
Button myButton = (Button)findViewById(R.id.my_button);
myButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MyFirstActivity.this, MySecondActivity.class);
startActivity(intent);
}
});
That being said, I don't recommend you to have two activities for this functionality. You should have different activities when you need different layouts. Putting the button and the textview in the same layout and updating textview inside the button's onclicklistener is a better solution.
I made 2 activities.
e.g] MainActivy and MediaActivity.
If user click home button in MediaActivity, App will hide.
I want launch MediaActivty again when screen on.
Open the gmail app, tap on an email to show it's contents. You have now gone from one activity (email list) to another (email details). Press the home button. Now open the gmail app again. Voila! You have returned to the email you selected.
What you ask for is the default behavior of an Android app. Unless you do something like call finish() in your onPause() method in MediaActivity you should return to MediaActivity when you open the app again.
If your app doesn't behave like this I suggest that you post some code.
Try to write your activities the following way :
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Put your own code here.
}
}
public class MediaActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Put your own code here.
}
}
What you're asking is Up Navigation / Ancestral Navigation(if I understood it correct). Refer to this guide: http://developer.android.com/training/implementing-navigation/ancestral.html
Othewise, if you want to have multiple instances of an activity, it's android:launchMode property should be set to standard in manifest. Refer:
http://developer.android.com/guide/topics/manifest/activity-element.html
I am really lost here.
I have an application which uses 3 XML files which each xml file is for each tabs ( i have 3 tabs with my app), which works fine. Under one of the tab there is a button, which when I click on it , it meant to pick up the name and number from the contact application and print it in that tab's screen, which is done by connecting to database and picking up names and number after being selected from the contact app. they all work fine.
But always after the process and picking up data and setting the textview values under the tb3, the main 3 tabs are disapeared and also all the 3 diffrent XML fileas are combined together Does anyone knows why?
Does anyone knows what to do ?any tutorial ?
someone suggested Fragmentmanager but I have no idea how to use that?
Pleas, please someone help me with this.
Here is the code for main activity which shows the tabs :
public class MainActivity extends TabActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
Button addbutton = (Button) findViewById(R.id.addButton);
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1",
res.getDrawable(R.drawable.tab1)).setContent(R.id.tab1Layout));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("tab2",
res.getDrawable(R.drawable.tab2)).setContent(R.id.tab2Layout));
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("tab3",
res.getDrawable(R.drawable.tab3)).setContent(R.id.tab3));
tabHost.setCurrentTab(2);
addbutton .setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MyActivity.this,ContactsDemo.class);
MainActivity.this.startActivityForResult(intent,1);
}
});
}
}
This suppose to open myActivity and then goes back to the MainAcitiviy. But after it loads the other activity, all three tabs disappears and all the three xml files combines.
Given your information I can only assume that addButton is a Button on one of your Tabs and that you want to return to the originating tab or one of the other two. I've built a similar app and I think you have to place the startActivityForResult()-call in one of the tab-activities, since you mentioned tb3 this would be a good start. When I do a startActivity() or startActivityForResult()-call and this new activity is closed or the user hits the back-button I'm back on my tab with the tabs-ribbon visible.
Hope this helps.
i`m trying to show indeterminate progress bar in ABS v. 4.0.2 by following code
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
getSherlock().setProgressBarIndeterminateVisibility(true);
}
on ICS virtual device it works fine, but progress do not shows in device with Android 2.1.
what i`m doing wrong?
Make sure you import com.actionbarsherlock.view.Window, not android.view.Window.
Try setSupportProgressBarIndeterminateVisibility(boolean) to get backward compatibility.
do this:
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.section_one1);
setSupportProgressBarIndeterminateVisibility(false);
on anything clickable like starting an activity via intent or adapters or whatever
show your progressbar on click
setSupportProgressBarIndeterminateVisibility(true);
but using this method when the user goes back to the activity the progress dialog will be visible still. There are many ways to stop it but the easiest one is just to use
#Override
public void onBackPressed()
{
NavUtils.navigateUpFromSameTask(this);
super.onBackPressed();
}
I found bunch of samples how to remove title/notification bar on Android. However, it's still not a full screen.
I still see a panel on my table with search, home, back and some other button.
Do you have any ideas how to hide this panel?
Generally speaking, I want kind of kiosk mode.
Use this code in onCreate of activity:
getWindow().setFlags(LayoutParams.FLAG_FULLSCREEN, LayoutParams.FLAG_FULLSCREEN);
Sample code for a fullscreen activity:
public class HellofullActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
where you request that the window has not the green title bar and take full screen.
The core problem was device specific. I was doing development for Archos and Archos has it's own bar, which isn't not removed by FLAG_FULLSCREEN and FEATURE_NO_TITLE