My apps won't display "KitKat" toast messages - android

So I just updated my phone to KitKat android 4.4.2 and the apps I made do not show the new themed KitKat toast. I import android.widget.Toast but still not showing the newly themed one. Is my ROM overriding it? However, Facebook does show the new toast. Not really important, just puzzled me.
Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "This toast is not kit kat", Toast.LENGTH_LONG).show();
}
});
}

Better use YourActivity.this instead of getApplicationContext()

Welp, after much confusion. I finally figured it out! :D
I decided to go to the Google source code for the toast notifications. I then decompiled my ROMs framework-res.apk and found the same source. However, i found an aditional source with a "tw" in front of it. This stands for "TouchWiz".
So simply, Samsung was overriding certain toast messages. I simply went and made both sources match the default source and now all my toasts are the nice neat KitKat toast themed :)
Thanks everyone for chatting with me about it!

Related

Android onClick not working on some android versions

I have set a couple of TextViews to call a method using the XML OnClick parameter. It works fine on a Lollipop device but it doesn't work on KitKat or older Android versions.
Why does it happen? Is there a way I can solve it without setting listeners for each view id?
Use android:clickable="true" in your textview.
In alternative, you can put your click logic in source code:
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
Without any code I have to assume that, since you're talking about challenges with pre-lollipop devices, you're having trouble with elevation values.
Check out this link:
Add elevation/shadow on toolbar for pre-lollipop devices

Toast in Fragment, should use getActivity() or getAcitivity().getApplicationContext()?

Sorry for my newbie Question, i just cannot find the answer from google and stackoverflow.. i just start learning for android, wish can build a good base for android knowledge. I wondering which i should use in the following if i create toast.maketext in fragment. getActivity() or getAcitivity().getApplicationContext()?
i did try both, it works well..
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getActivity(), "hello",Toast.LENGTH_LONG).show();
Toast.makeText(getActivity().getApplicationContext(),"Hello",Toast.LENGTH_LONG).show();
}
});
For user interface related calls use the Activity context.
See this explanation by Reto Meier:
https://stackoverflow.com/a/987503/534471

How to make OnDrawerOpenListener() work in android

Can someone explain how to get this to work please. Says its deprecated, just wondering if I can force it or if there is another way to change my title label when the SlidingDrawer is opened then change it back when it is closed. I still have a lot to learn so if possible please reply with something that is cut and paste friendly ;) Thanks.
Jesse
OnDrawerCloseListener onClick_DrawerClosed = new OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
titletext.setText("Flow Charts");
}
};
OnDrawerOpenListener onClick_DrawerOpened = new OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
titletext.setText("Options Menu");
}
};
SlidingDrawer in general is deprecated as of API 17 (the latest). This doesn't mean you can't use SlidingDrawer and it's methods, but that it's "frowned upon" and Eclipse will give you warnings. You can make those go away by right clicking on the warnings and selecting "Suppress..."
Look here for a more thorough discussion:
SlidingDrawer deprecated

Android java.lang.NoSuchFieldError

In some case, when accessing an activity field from an anonymous class, I get NoSuchFieldError at runtime: java.lang.NoSuchFieldError: MyActivity.myField
EDIT: I'm now sure that it's an Android issue, because everything compiles correctly but resolved incorrectly at runtime. When changing to MyActivity.this.myField instead of plain myField, everything works perfect.
BTW, I rechecked and I don't have any other myField anywhere else, Also, when opening declaration in Eclipse, it goes to the intended field (myField).
The only problem is that I couldn't reproduce this in a sample project. I'm left only to state that it's a specific problem in my project, but I'm reluctant doing so and I can't publish this project.
I'll keep this open in case someone stumbles upon something similar.
Here's the code that I can publish that crashes my project but not the sample one:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Runnable() {
#Override
public void run() {
Toast.makeText(MyActivity.this, myField.getName(), Toast.LENGTH_SHORT).show();
}
}.run();
}
It seems that accessing the field with the class' prefix solves it: MyActivity.this.myField
Strange. I guess it's something with Android's field resolution in runtime.

How design a button in Eclipse for Android App, so when you click, it takes you to a website

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.

Categories

Resources