Android ActionBarSherlock ProgressBar always Indeterminate - android

I've got an activity that extends SherlockActivity but the progressbar is always indeterminate, even without setting it to true or after setting it to false.
I've already checked the import:
import com.actionbarsherlock.view.Window;
The activity in fact extends Sherlock:
public class MyActivity extends SherlockActivity {
Here is the onCreate method:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setProgressBarIndeterminate(false);
setSupportProgressBarIndeterminateVisibility(false);
In no place I set it to true, but it still appears without leaving.
The manifest:
<activity
android:name=".activities.MyActivity"
android:screenOrientation="portrait" >
</activity>
Any ideas of what might be causing this?
Thank you!

I am just enabling and disable the ActionBarShareLock ProgressBar.
Not sure but might be helpful to you.
Below is my code:
public class IndeterminateProgress extends SherlockActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(SampleList.THEME); //Used for theme switching in samples
super.onCreate(savedInstanceState);
//This has to be called before setContentView and you must use the
//class in com.actionbarsherlock.view and NOT android.view
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.iprogress);
findViewById(R.id.enable).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
setSupportProgressBarIndeterminateVisibility(true);
}
});
findViewById(R.id.disable).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
setSupportProgressBarIndeterminateVisibility(false);
}
});
}
}
Updated
have you try with this:
getSherlock().setProgressBarIndeterminate(indeterminate);
OR
getSherlock().setProgressBarVisibility(visible);
I mean try with call getSherlock() before going to Ideterminate or change its visibility.
Let me comment of result.
Hope this will help you.

Try out as below:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.browser);
setProgressBarIndeterminateVisibility(true);
setProgressBarVisibility(true);
findViewById(R.id.enable).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
setProgressBarIndeterminateVisibility(false);
setProgressBarVisibility(false);
}
});
}

Well,
I can't find an explanation for why it is always indeterminate.
Also, this definitely is not working
getSherlock().setProgressBarIndeterminate(false);
However using
getSherlock().setProgressBarIndeterminateVisibility(false);
seems to solve the issue.

do this
just before you declare your activity view pass the progress bar and after defining your view disable the visibility of the progress bar then on your whatever click enable the visivility of the bar
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.yourlayout);
setSupportProgressBarIndeterminateVisibility(false);
......
......
.........
...OnClick()
{
setSupportProgressBarIndeterminateVisibility(true);
}
.............

It was the same problem I had and it taken me 5 hours to debug ABS to investigate the problem. The solution is very simple:
Use:
com.actionbarsherlock.view.Window.FEATURE_INDETERMINATE_PROGRESS
Like:
requestWindowFeature(com.actionbarsherlock.view.Window.FEATURE_INDETERMINATE_PROGRESS);
Instead of:
android.view.Window.FEATURE_INDETERMINATE_PROGRESS

Related

Context Argument in Toast.maketext()

this is my first post here. I used the search function and could not find a complete answer,so I hope this is not a redundant question.
I should note that I m really new to coding so maybe I did find an answer but did not realise it.
I have been asked in class to find two different ways to fill the argument in the code below.
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(this);
}
#Override
public void onClick(View v) {
Toast.makeText(???,"Clicked!", Toast.LENGTH_LONG).show();
the first way i suppose would be toast.makeText(MainActivity.this.getActivity(),....).show();
the second one?
Use the MainActivity context.
Toast.makeText(MainActivity.this,"Clicked!", Toast.LENGTH_LONG).show();
v.getContext() and this both can be used

How do I open android Text to speech settings from preference screen?

I am trying to open the android default TTS settings whenever I click on the particular preference in my App settings. My pref_settings.xml looks like this:
<PreferenceScreen
android:key="Lang_Select"
android:title="Language"
android:summary="Select a Language">
</PreferenceScreen>
This is my list in android settings. and my SettingsActivity.java looks like this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
}
public static class ChatSettingsFragment extends PreferenceFragmentCompat {
#Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.pref_settings);
}
}
#Override
public void onBackPressed() {
super.finish();
}
}
How can I start the android default TTS settings whenever the language button is clicked?
Thanks.
I have not worked with PreferenceFragmentCombat only with normal PreferenceFragment, but I guess it´s not that much difference in the basic implementations. So please, be noticed that this is maybe not the answer for your problem, but I try to help you a little bit and have to show some code. I have done it in my onCreate() method like this:
public class PreferenceFragment extends android.preference.PreferenceFragment {
private Preference mYourPreference;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference_layout);
//initialize your preference with the key you used in xml layout
mYourPreference=(Preference)getPreferenceManager().findPreference(yourPreferenceKey);
//set on click listener
mYourPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
#Override
public boolean onPreferenceClick(Preference preference) {
//start the activity
startActivity(new Intent(android.provider.Settings.ACTION_VOICE_INPUT_SETTINGS), 0);
return true;
}
});
}
}
I don´t know if ACTION_VOICE_INPUT_SETTINGS will work, just try it.
Try this:
startActivity(Intent("com.android.settings.TTS_SETTINGS"))
See: https://cs.android.com/android/platform/superproject/+/master:cts/apps/CtsVerifier/src/com/android/cts/verifier/speech/tts/TtsTestActivity.java;l=21?q=TTS_SETTINGS

Use Toolbar as ActionBar in ALL Activities without programmatically doing it in each Activity

I've placed the following code in onCreate() to set a toolbar I use in each Activity as the ActionBar:
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
This works fine and shows the back arrow and title in each Activity, and is necessary because we add custom content to our ToolBar, but it's messy and annoying to have to do this in each Activity.
What's the best way to achieve this behavior without the duplication? Can it be done in styles?
You should create Base Activity like this :
public class Base extends AppCompatActivity {
TextView icon1;
#Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
initToolbar()
}
public void initToolbar() {
.
.
.
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
if (showIcon1())
icon1.setVisibility(View.VISIBLE);
else
icon1.setVisibility(View.GONE);
}
public boolean showIcon1(){
return true;
}
And other activity :
public class OtherActivity extends Base {
#Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
}
#Override
public boolean showIcon1() {
return false;
}<br>
Hope this Help.
I'm not sure if "best" but if you really want that in all your activities you have two choices:
Inheritance: A very common Android/Java approach is to subclass Activity and then use that as your base. E.g.:
public class BaseActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupToolbar();
}
private void setupToolbar() {
// do whatever you need to do
}
}
public class YourFancyClass extends BaseActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Do anything you need to. The toolbar is set by the base class.
}
}
That's one option (very popular)
Plan B would be to use Composition, mostly preferred in the iOS side, yet still very valid (and sometimes more appropriate, a discussion we're not having now) :)
Basically have an object that is capable of setting your toolbar. Create an interface that can represent that behavior. Have an implementation of such behavior (Java usually calls them XxxxxImpl and have that interface and implementation passed onto the activities that need it.
Sounds more complicated, but it's very clean and clear once you got it all together.

Butterknife not detecting the source of event

I have just started working with Butterknife library and written the following code:
class myActivity extends AppCompatActivity
{
#BindView(R.id.button) Button app1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
public void selectApp(View b)
{
Button clicked=(Button)b;
if(clicked==app1)
Toast.makeText(this,"First App clicked",Toast.LENGTH_LONG).show();
}
}
here selectApp is attached through onClick in the xml view file.
But the problem is clicked==app1 is returning false even when pressing app1. The method is being called but the if condition is coming false.
Can anybody clarify.
Thanks
I think this would work:
if(clicked.getId()==R.id.button)
Also, you can use View b and not parse into a button:
if(b.getId()==R.id.button)
¿Is this your actual code? seems to lack an annotation on the method.

Layout cannot be removed

I am trying to remove the layout when the apps starts.
I removed "setContentView" from the MainActivity.java file but still the layout is showing when the activty starts..
How can I remove the layout??
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setVisible(false);
}
}
try adding this to your manifest, inside activity android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"

Categories

Resources