I am trying to make an xposed module(private use) to implement clear all button(ImageView) in recents.
Here is my code
Code:
package com.mycompany.myapp3;
import android.graphics.*;
import android.view.*;
import android.widget.*;
import de.robv.android.xposed.*;
import de.*;
import de.robv.android.xposed.callbacks.*;
import de.robv.android.xposed.callbacks.XC_LoadPackage.*;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
public class MainActivity implements IXposedHookLoadPackage
{ImageView m;
String rc="com.android.systemui.recent.RecentsPanelView";
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable
{
findAndHookMethod(rc, lpparam.classLoader, "updateClock", new XC_MethodHook() {
@Override
protected void afterHookedMethod(final MethodHookParam param) throws Throwable
{
m.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
ViewGroup mRecentsContainer = (ViewGroup) XposedHelpers.getObjectField(
param.thisObject, "mRecentsContainer");
// passing null parameter in this case is our action flag to remove all views
mRecentsContainer.removeViewInLayout(null);
}
});
}
});
}}
Now the problem is that i have already that ImageView in recent_panel.xml with no action assigned.i know its id and want to implement onclick action to that ImageView only by using its id.so what code should i add so that code recognises that ImageView and assigns it the above onclick action
Sent from my GT-S5570 using XDA Premium 4 mobile app
It's only an idea and maybe it doesn't solve your problem: Have you tried to hook onCreate and use the this-Object to call findViewById?
And you are making a mistake: You have to look, whether the loaded package is your specific package you want to hook. You try to hook every app.
Regards
EmptinessFiller said:
It's only an idea and maybe it doesn't solve your problem: Have you tried to hook onCreate and use the this-Object to call findViewById?
And you are making a mistake: You have to look, whether the loaded package is your specific package you want to hook. You try to hook every app.
Regards
Click to expand...
Click to collapse
1. this-object.?Can you give an example?
2.yes you are right i will fix it
Sent from my GT-S5570 using XDA Premium 4 mobile app
Sth. like m = (ImageView) ((Activity) param.thisObject).findViewById(id);
(Not tested)
EmptinessFiller said:
Sth. like m = (ImageView) ((Activity) param.thisObject).findViewById(id);
(Not tested)
Click to expand...
Click to collapse
I have got the solution already.thanks for your help
Sent from my GT-S5570 using XDA Premium 4 mobile app
Related
Im trying to create an currency conversion app but nothing happens when i click on the convert button. Here is the code i followed the tutorial.
package com.currencyconverter;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;
public class currencyconverter extends Activity implements OnClickListener {
/** Called when the activity is first created. */
TextView dollars;
TextView euros;
RadioButton dtoe;
RadioButton etod;
Button convert;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
dollars = (TextView)this.findViewById(R.id.dollars);
euros = (TextView)this.findViewById(R.id.euros);
dtoe = (RadioButton)this.findViewById(R.id.dtoe);
dtoe.setChecked(true);
etod = (RadioButton)this.findViewById(R.id.etod);
convert = (Button)this.findViewById(R.id.Convert);
convert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
@Override
public void onClick(View v) {
if (dtoe.isChecked()) {
convertDollarsToEuros();
}
if (etod.isChecked()) {
convertEurosToDollars();
}
}
// TODO Auto-generated method stub
protected void convertEurosToDollars(){
double val = Double.parseDouble(euros.getText().toString());
dollars.setText(Double.toString(val/0.67));
}
protected void convertDollarsToEuros(){
double val = Double.parseDouble(dollars.getText().toString());
euros.setText(Double.toString(val*0.67));
}
}
You dont handle clicks
Sent from my Acer Liquid using XDA App
In which part in my program I add /change or remove handle clicks. Thanks.
Sent from my GT-I9000 using XDA Premium App
I cant see it that good on my phone. But try to use the first overridden
Method instead of creating a new one
Sent from my Acer Liquid using XDA App
Which overriden referring to.
Sent from my GT-I9000 using XDA Premium App
The area that has the first "//TODO" is what gets executed when you click. Put the code there. Remove the second onClick stuff.
Try this code
Code:
convert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (dtoe.isChecked()) {
convertDollarsToEuros();
} else if (etod.isChecked()) {
convertEurosToDollars();
}
}
});
I'll try it after work. I'll let you know if it works. Thanks.
Sent from my GT-I9000 using XDA Premium App
Ok. That worked. But now two problems. One, if I enter nothing and press convert it force closes. Two, when it calculates the number keep screwing up. Example, pending on conversion, in one of the box fields I can see partial digits.
Sent from my GT-I9000 using XDA Premium App
You should implement a Check if something was entered of course
Sent from my Liquid using XDA App
I have a viewpager with four webview fragments. Im trying to get a GoBack Action to my WebView which is inside of a fragment. But i cant implement it right into my code here is the code of my webview in my fragments. I also can't seem to get a downloadListener to work either. Sorry I am kinda new to fragments and trying to understand how they work.
Code:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings.RenderPriority;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
public class Fragment1 extends Fragment {
private static final String WebSettings = null;
private WebView webView;
private Bundle webViewBundle;
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.fragment_1,
container, false);
webView = (WebView) ll.findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setLoadWithOverviewMode(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setRenderPriority(RenderPriority.HIGH);
if (webViewBundle == null) {
try{
webView.loadUrl("http://www.google.com");
}catch (Exception e){
e.printStackTrace();}
} else {
webView.restoreState(webViewBundle);
}
return ll;
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
[user=439709]@override[/user]
public void onPause() {
super.onPause();
webViewBundle = new Bundle();
webView.saveState(webViewBundle);
}
}
dfuse06 said:
I have a viewpager with four webview fragments. Im trying to get a GoBack Action to my WebView which is inside of a fragment. But i cant implement it right into my code here is the code of my webview in my fragments. I also can't seem to get a downloadListener to work either. Sorry I am kinda new to fragments and trying to understand how they work.
Code:
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings.RenderPriority;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
public class Fragment1 extends Fragment {
private static final String WebSettings = null;
private WebView webView;
private Bundle webViewBundle;
[user=439709]@override[/user]
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.fragment_1,
container, false);
webView = (WebView) ll.findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setLoadWithOverviewMode(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setRenderPriority(RenderPriority.HIGH);
if (webViewBundle == null) {
try{
webView.loadUrl("http://www.google.com");
}catch (Exception e){
e.printStackTrace();}
} else {
webView.restoreState(webViewBundle);
}
return ll;
}
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
[user=439709]@override[/user]
public void onPause() {
super.onPause();
webViewBundle = new Bundle();
webView.saveState(webViewBundle);
}
}
Click to expand...
Click to collapse
You will need to override the onKeyUp method in the Activity. Then search for the fragment there and call a method of your subclass of Fragment which you want to be executed when the back key is pressed.
nikwen said:
You will need to override the onKeyUp method in the Activity. Then search for the fragment there and call a method of your subclass of Fragment which you want to be executed when the back key is pressed.
Click to expand...
Click to collapse
So I can't actually do this inside the fragment?
Sent from my SCH-I535 using Tapatalk 2
dfuse06 said:
So I can't actually do this inside the fragment?
Sent from my SCH-I535 using Tapatalk 2
Click to expand...
Click to collapse
I do not think so.
nikwen said:
I do not think so.
Click to expand...
Click to collapse
That must be all my errors then.
Sent from my SCH-I535 using Tapatalk 2
nikwen said:
You will need to override the onKeyUp method in the Activity. Then search for the fragment there and call a method of your subclass of Fragment which you want to be executed when the back key is pressed.
Click to expand...
Click to collapse
could you post a example on how it should look. This is driving me nuts nothing is working
dfuse06 said:
could you post a example on how it should look. This is driving me nuts nothing is working
Click to expand...
Click to collapse
Google!!!
Check those:
http://stackoverflow.com/questions/12210906/fragment-activity-catch-onkeydown-and-use-in-fragment
http://stackoverflow.com/questions/10631425/android-webview-inside-fragment-how-to-add-goback
nikwen said:
Google!!!
Check those:
http://stackoverflow.com/questions/12210906/fragment-activity-catch-onkeydown-and-use-in-fragment
http://stackoverflow.com/questions/10631425/android-webview-inside-fragment-how-to-add-goback
Click to expand...
Click to collapse
lol!!! I have googled it. Looked on stackoverflow posted on stack
http://stackoverflow.com/questions/16379973/goback-and-download-listener-in-webview-fragment
tried all kinda codes I found from there and no luck!
dfuse06 said:
lol!!! I have googled it. Looked on stackoverflow posted on stack
http://stackoverflow.com/questions/16379973/goback-and-download-listener-in-webview-fragment
tried all kinda codes I found from there and no luck!
Click to expand...
Click to collapse
Post your code (or the important parts of it) so that we can find your errors.
Having the same issue
dfuse06 said:
lol!!! I have googled it. Looked on stackoverflow posted on stack
tried all kinda codes I found from there and no luck!
Click to expand...
Click to collapse
I'm having the same issue. Did you find resolution? If so, please post it.
Basically I created a button on my app which links it to another java class. I already setted the layout for the java class using the setContentView method.
But whenenever I click on the button, it doesn't take me to that java class. Im still practising right now but ive gone through the whole project nd couldn't find whats going wrong. I literally cant find any errors.
This is what I did to link the button:
Code:
package com.tarikh.thebasics;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class splash extends Activity{
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button tut1 = (Button) findViewById(R.id.button1);
tut1.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.tarikh.thebasics.TUTORIALONE"));
}
});
}
as you can see, the tutorialone class has the following layout:
Code:
public class TUTORIALONE extends Activity {
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial1);
and the tutorial1.xml layout consists of a radiobutton (this is just rough). so whenever I click on the button, it should take me to the tutorialone class right?
Try:
Code:
Intent intent = new Intent(splash.this, TUTORIALONE.class);
startActivity(intent);
TwilightLoz said:
Basically I created a button on my app which links it to another java class. I already setted the layout for the java class using the setContentView method.
But whenenever I click on the button, it doesn't take me to that java class. Im still practising right now but ive gone through the whole project nd couldn't find whats going wrong. I literally cant find any errors.
This is what I did to link the button:
Code:
package com.tarikh.thebasics;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class splash extends Activity{
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button tut1 = (Button) findViewById(R.id.button1);
tut1.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.tarikh.thebasics.TUTORIALONE"));
}
});
}
as you can see, the tutorialone class has the following layout:
Code:
public class TUTORIALONE extends Activity {
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial1);
and the tutorial1.xml layout consists of a radiobutton (this is just rough). so whenever I click on the button, it should take me to the tutorialone class right?
Click to expand...
Click to collapse
zalez said:
Try:
Code:
Intent intent = new Intent(splash.this, TUTORIALONE.class);
startActivity(intent);
Click to expand...
Click to collapse
Nope, that doesn't work. I don't know why but I have a feeling its something got to do with my emulator. I think its not set up right..
Is there any output from the logcat?
zalez said:
Is there any output from the logcat?
Click to expand...
Click to collapse
Nope, that's the weird thing. I think there is something wrong with the emulator since it does lag alot when I run it and also I cant use the home button, back button and the search button on the emulator...
I would start by deleting your emulator and recreating it. Then if that doesn't work, I would backup any code you want to keep and start deleting your ide environment and android sdk and just start over.
Ive actually done that yesterday since something went wrong with the saving of my project so my project was deleted. Today I started over. Guess im going to have to start from fresh. Oh by the way, can you have a look over here and answer my question:
http://forum.xda-developers.com/showthread.php?t=2343814
actually I just checked the logcat and I do infact have 1 error. I attached the screenshot of it:
TwilightLoz said:
actually I just checked the logcat and I do infact have 1 error. I attached the screenshot of it:
Click to expand...
Click to collapse
This should not be an error of your app.
nikwen said:
This should not be an error of your app.
Click to expand...
Click to collapse
You mean that the error has nothing to do with my app? But now it wont let me run it since im getting that error!! I actually deleted EVERYTHING again and now im going to start fresh again (at least its good practise).
Could you give me the links to get the eclipese and the androis sdk/adt? Since ive downloaded all of them 3 times...
TwilightLoz said:
You mean that the error has nothing to do with my app? But now it wont let me run it since im getting that error!! I actually deleted EVERYTHING again and now im going to start fresh again (at least its good practise).
Could you give me the links to get the eclipese and the androis sdk/adt? Since ive downloaded all of them 3 times...
Click to expand...
Click to collapse
Of course, here you go: http://developer.android.com/sdk/installing/installing-adt.html
You say that it does not let you run the app. Can you install it? I guess that you cannot. Even if you could, there would be a bigger log output/stacktrace.
There should be errors shown in your IDE (Eclipse). Is there any red sign in your project code? (If there is one, there will be a red X in the Package Explorer view.)
I think that the problem is in your code.
Check this.
nikwen said:
Of course, here you go: http://developer.android.com/sdk/installing/installing-adt.html
You say that it does not let you run the app. Can you install it? I guess that you cannot. Even if you could, there would be a bigger log output/stacktrace.
There should be errors shown in your IDE (Eclipse). Is there any red sign in your project code? (If there is one, there will be a red X in the Package Explorer view.)
I think that the problem is in your code.
Check this.
Click to expand...
Click to collapse
I just deleted everything apart from my project before reading your reply...
I'll download it again and run my project again. I didnt get any red x by the way.
TwilightLoz said:
Basically I created a button on my app which links it to another java class. I already setted the layout for the java class using the setContentView method.
But whenenever I click on the button, it doesn't take me to that java class. Im still practising right now but ive gone through the whole project nd couldn't find whats going wrong. I literally cant find any errors.
This is what I did to link the button:
Code:
package com.tarikh.thebasics;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class splash extends Activity{
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button tut1 = (Button) findViewById(R.id.button1);
tut1.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.tarikh.thebasics.TUTORIALONE"));
}
});
}
as you can see, the tutorialone class has the following layout:
Code:
public class TUTORIALONE extends Activity {
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial1);
and the tutorial1.xml layout consists of a radiobutton (this is just rough). so whenever I click on the button, it should take me to the tutorialone class right?
Click to expand...
Click to collapse
First of all, I would make the Button variables as a "Field" Rather than a 1-time instance of your onCreate() method. A Field is a variable defined at the root of your Class. Example:
Code:
package com.tarikh.thebasics;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class splash extends Activity{
[COLOR="Lime"]Button tut1;[/COLOR]
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
[COLOR="lime"]tut1 [/COLOR]= (Button) findViewById(R.id.button1);
tut1.setOnClickListener(new View.OnClickListener() {
[user=439709]@override[/user]
public void onClick(View v) {
[COLOR="lime"] if (v.getId() == R.id.button1) {
startActivity(new Intent("com.tarikh.thebasics.TUTORIALONE"));
}[/COLOR]
}
});
}
The Lime-Green colored text is the only thing that needs to be change.
The 1st is now a Field, where that variable will be seen throughout the whole class, not just onCreate().
Then take away the Button declaration of tut1 in your onCreate() Method. this will make the tut1 Field (Button) = (your_id_here)
Edit: sorry, I misread. Disregard the "if " statement.
Cheers
1. Try it on a device if you can. I never use AVDs because I can run and debug an app about 8 times before my AVD even loads. Plus yours seems buggy.
2. Does it force close or just not work? if it FCs make sure you declared the second activity in your manifest.
3. Does the main xml button have an id?-- android:id="@+id/button1" ?
EDIT. Wait, your button should be in the activity_main.xml, not tutorialone. if its in tutorial one it weould try to reload that same activity.
actually it wouldnt even do anything probably, because your calling a button that isnt where you are.
Thanks for all your suggestions. I think I'm going to start fresh since Ive got more knowledge now. I'll take all your advices on board and if things go wrong, i'll post my problem here.
nikwen said:
Of course, here you go: http://developer.android.com/sdk/installing/installing-adt.html
You say that it does not let you run the app. Can you install it? I guess that you cannot. Even if you could, there would be a bigger log output/stacktrace.
There should be errors shown in your IDE (Eclipse). Is there any red sign in your project code? (If there is one, there will be a red X in the Package Explorer view.)
I think that the problem is in your code.
Check this.
Click to expand...
Click to collapse
Im going to download this as this has everything bundled together:
http://developer.android.com/sdk/index.html
Thanks guys for your co-operation, I just created the splash page and linked the button to the other layout. Got error but fixed them. It was good practice.
Didn't know running the app from your device instead of the emulator would be soo easy!! And not to mention less laggy.
TwilightLoz said:
Thanks guys for your co-operation, I just created the splash page and linked the button to the other layout. Got error but fixed them. It was good practice.
Didn't know running the app from your device instead of the emulator would be soo easy!! And not to mention less laggy.
Click to expand...
Click to collapse
Great.
Hey guys, im on the process of building my app. Basically, so far, this is what should happen:
The user presses a button and a dialogbox appears. In the dialogbox, the user selects the days in which the reminder shall remind him. (If that makes sense...).
This is my Java code:
Code:
package yCM.medireminder;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class ADD extends Activity implements OnClickListener{
private AlertDialog.Builder dialogBuilder;
private void days()
{
//Declaring the Variables
final ArrayList weekdays = new ArrayList();
dialogBuilder = new AlertDialog.Builder(this);
final String[] dayss = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
//Starting the Process
dialogBuilder.setTitle("Check the Days");
dialogBuilder.setMessage("Check the days when you will shall be reminded");
dialogBuilder.setMultiChoiceItems(dayss, null, new DialogInterface.OnMultiChoiceClickListener() {
[user=439709]@override[/user]
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
weekdays.add(which);
}else if(weekdays.contains(which))
{
weekdays.remove(Integer.valueOf(which));
}
}
});
dialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
[user=439709]@override[/user]
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Your days have been set", Toast.LENGTH_LONG);
}
});
dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
[user=439709]@override[/user]
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Your days have not been set", Toast.LENGTH_LONG);
}
});
// OUTPUT
AlertDialog dayDialog = dialogBuilder.create();
dayDialog.show();
}
Does everything look alright, the emulator isn't working for my and I have misplaced my phone (its on silent) so I have no way of checking whether it will work. I have linked the dialog box to a button so Im sure that when the button is clicked, the dialog box should appear.
It is recommended to use DialogFragments instead of simple dialogs. That way the system would orientation changes etc. for you.
However, you would need to convert your Activity into a FragmentActivity.
nikwen said:
It is recommended to use DialogFragments instead of simple dialogs. That way the system would orientation changes etc. for you.
However, you would need to convert your Activity into a FragmentActivity.
Click to expand...
Click to collapse
I do plan on making the app on permenantly on portrait mode so I don't think the orientation would be any problem even when the user switches to landscape.
Why would I need to convert my activity to fragmentactivity? What does this do? Also my min sdk is set to api level 8 (2.2 i believe).
Other than that, does the code seem alright?
TwilightLoz said:
I do plan on making the app on permenantly on portrait mode so I don't think the orientation would be any problem even when the user switches to landscape.
Why would I need to convert my activity to fragmentactivity? What does this do? Also my min sdk is set to api level 8 (2.2 i believe).
Other than that, does the code seem alright?
Click to expand...
Click to collapse
You just need to do this if you want to use the DialogFragment. For the normal dialog you don't need it.
You can use fragments on Android 1.6+ if you include the supportv4 library.
Try it. That's all I can say. There might be other things that make it crash, apart from that code. Maybe related to the Android lifecycle.
thanks for the info. Just runned it, everythings working smooth for now. Any idea on how to make the android system recognise/link the days of the week on my string? I did have a read through this but didn't quite understand it. I have a feeling that I should be using something got to do with the calender though...
http://developer.android.com/reference/java/util/Date.html#getDay()
TwilightLoz said:
thanks for the info. Just runned it, everythings working smooth for now. Any idea on how to make the android system recognise/link the days of the week on my string? I did have a read through this but didn't quite understand it. I have a feeling that I should be using something got to do with the calender though...
http://developer.android.com/reference/java/util/Date.html#getDay()
Click to expand...
Click to collapse
You can get the current time using
Code:
System.currentTimeMillis()
Then create a Date from it:
Code:
Date myDate = new Date(System.currentTimeMillis();
Then you can format it using the SimpleDateFormat class: http://developer.android.com/reference/java/text/SimpleDateFormat.html
For some things the Calendar class might be better: http://developer.android.com/reference/java/util/Calendar.html
However, I have not worked with it yet.
Im new to app development and im having trouble adding a menu to my app. Im using eclipse. I don't get any errors but when I start the app and press the menu button on my phone nothing happens.
Code:
package com.JEB.mybills;
import android.annotation.TargetApi;
import android.app.ListFragment;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
public class ReminderListFragment extends ListFragment {
[user=439709]@override[/user]
public void onActivityCreated (Bundle savedInstanceState){
super.onActivityCreated (savedInstanceState);
setEmptyText (getResources() .getString(R.string.no_reminders));
}
private ListAdapter mAdapter;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
String[] items = new String[] {"Foo", "Bar", "Fizz", "Bin"};
mAdapter = new ArrayAdapter<String>(getActivity(),
R.layout.reminder_row, R.id.text1, items);
setListAdapter(mAdapter);
}
public void onListItemClick(ListView l, View v, int position, long id){
super.onListItemClick(l, v, position, id);
Intent i = new Intent(getActivity(), ReminderEditActivity.class);
i.putExtra(ReminderProvider.COLUMN_ROWID, id);
startActivity(i);
}
public void onViewCreate(Bundle savedInstanceState){
super.onViewCreated (getView(), savedInstanceState);
registerForContextMenu(getListView());
setHasOptionsMenu(true);
}
[user=439709]@override[/user]
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.list_menu, menu);
}
[user=439709]@override[/user]
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.menu_insert:
editReminder(0);
return true;
}
return super.onOptionsItemSelected(item);
}
[user=439709]@override[/user]
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo
menuInfo){
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater mi = getActivity().getMenuInflater();
mi.inflate(R.menu.list_menu_item_longpress, menu);
}
public void editReminder(long id){
Intent i=new Intent(getActivity(), ReminderEditActivity.class);
i.putExtra(ReminderProvider.COLUMN_ROWID, id);
startActivity(i);
}
public boolean onCrontextItemSelected(MenuItem item){
switch(item.getItemId()){
case R.id.menu_delete:
//Delete the task
return true;
}
return super.onContextItemSelected(item);
}}
jeb192004 said:
Im new to app development and im having trouble adding a menu to my app. Im using eclipse. I don't get any errors but when I start the app and press the menu button on my phone nothing happens.
Click to expand...
Click to collapse
First I have to say that using the "CODE /CODE" tags (obviously with "[ ]") would be a good idea, when posting so that it looks better
Code:
@override
public void onActivityCreated (Bundle savedInstanceState){
super.onActivityCreated (savedInstanceState);
setEmptyText (getResources() .getString(R.string.no_reminders));
}
Your not very clear but I assume, you want something to happen when you press the physical menu key on your device ? If so I don't see anything that captures the event of this key ? Or am I missing something ? If I wanted to close my app by pressing a physical menu key I would probably do something like
Code:
@Override
public boolean onKeyDown(int keycode, KeyEvent e) {
switch(keycode)
{
case KeyEvent.KEYCODE_MENU:
this.finish();
break;
}
return super.onKeyDown(keycode, e);
}
But not all devices have physical menu keys. My answer is based on assumptions and guess work of what your wanting
My phone has the menu button on the screen.(LG g flex)
Sent from my LG-LS995 using xda app-developers app
deanwray said:
Code:
@Override
public boolean onKeyDown(int keycode, KeyEvent e) {
switch(keycode)
{
case KeyEvent.KEYCODE_MENU:
this.finish();
break;
}
return super.onKeyDown(keycode, e);
}
But not all devices have physical menu keys. My answer is based on assumptions and guess work of what your wanting
Click to expand...
Click to collapse
where you have
Code:
return super.onKeyDown(keycode, e);
I get an error saying its "undefined for the type ListFragment"
jeb192004 said:
where you have
Code:
return super.onKeyDown(keycode, e);
I get an error saying its "undefined for the type ListFragment"
Click to expand...
Click to collapse
I never said your phone didn't have a menu key (I obviously assumed it did, was just saying not all do)
The error is because your inside a fragment, that while has access to Context does not have direct reference. Overriding a key is for Activity/FragmentActivity/Application context
deanwray said:
I never said your phone didn't have a menu key (I obviously assumed it did, was just saying not all do)
The error is because your inside a fragment, that while has access to Context does not have direct reference. Overriding a key is for Activity/FragmentActivity/Application context
Click to expand...
Click to collapse
So...Everything for my menu go into the activity? Not my fragment?
I been trying to learn form "Android Application Development For Dummies" and its telling me to put it all in my fragment...
Ok...I got your code to work and it exited the app but now I'm having trouble getting it to open my options menu
jeb192004 said:
Ok...I got your code to work and it exited the app but now I'm having trouble getting it to open my options menu
Click to expand...
Click to collapse
well thats unrelated, you mean you dont know in android how to open the options menu ? There are simple tutorials on it on d.android.com you should have a read, lots of good info there