to provide a list option i would like to use a context menu, is it possible to open a context menu through a onClick intent? if so how ?
thanks
Related
I created listView item which contain list using following command and watched it working:
lv1=(ListView)findViewById(R.id.listView_entries);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, PENS));
However, I wonder if it is possible to have it attribute so that
clicking on single item will move to another activity, however clicking on the checkbox will highlight the listitem without moving to another activity?
Currently, I implemented onclick function on listView so that clicking on any item will go to another activity. However, does clicking on the checkbox on each item.
Thanks,
I'm not sure I follow you completely on this, but it should do what you want if you supply an OnClickHandler for the checkbox. You may need to expand the padding on the checkbox control to ensure that you hit it and not the list entry around it.
hey i think i found a solution to this, i found it in the pro android training manual. i will post once i am able to integrate into my code. thx.
I want to set default home application when user click my menu.
So, I make this code and resolveractivity is shown when I click my menu.
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
intent.setComponent(new ComponentName("android","com.android.internal.app.ResolverActivity"));
startActivity(intent);
But, although I choose any applications in the resolver activity, default application isn't applied.
Why default home application isn't changed?
HI Guys
This is my first post in android app developement forum.
A small snippet of code which I use to exit from android app .
Many times we have more than one activites in app and often these activities are inter linked.
suppose we have four activities A-> B- ->C->D with A as root activity
Now consider user move from A to B then B--> C then come to A and moves to D
Now when user press back he returns to A
At this some app requires to be close and it should not navigate in history of activity stack ie
going to B then C then again A and finaly exit.
So the solution here is to close the app when user is in A acitivity since its Root activity.
Below is the code for that:
Code:
private static long back_pressed;
private Toast toast;
[user=439709]@override[/user]
public void onBackPressed()
{
if (back_pressed + 2000 > System.currentTimeMillis())
{
// need to cancel the toast here
toast.cancel();
// code for exit
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else
{
// ask user to press back button one more time to close app
toast= Toast.makeText(getBaseContext(), "Press once again to exit!", Toast.LENGTH_SHORT);
toast.show();
}
back_pressed = System.currentTimeMillis();
}
Add this code in your root activity so that it wont let app go into history stack.
Also you may write dialog instead of toast message
:good:
Nice snippet, thanks!
Sent from my GT-N7000 using Tapatalk 4
I can't for the life of me find ANYTHING written about how to create a shortcut to an app. All over stackoverflow it's just about having ones app get created as a shortcut onto users own launcher.
I want the user to be able to click my button which opens a dialog, in where the user can then select an app of their choosing, rename the shortcut and lastly hit the "Ok" button which should then let that app sit in my apps fragment until the user decides to remove it.
How would I go about doing this?
nex7er said:
I can't for the life of me find ANYTHING written about how to create a shortcut to an app. All over stackoverflow it's just about having ones app get created as a shortcut onto users own launcher.
I want the user to be able to click my button which opens a dialog, in where the user can then select an app of their choosing, rename the shortcut and lastly hit the "Ok" button which should then let that app sit in my apps fragment until the user decides to remove it.
How would I go about doing this?
Click to expand...
Click to collapse
To get a list of all installed applications, use
Code:
final PackageManager pm = getPackageManager(); //get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
To start them just create a new Intent(packageName) and start it with startActivity(intent);
SimplicityApks said:
To get a list of all installed applications, use
Code:
final PackageManager pm = getPackageManager(); //get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
To start them just create a new Intent(packageName) and start it with startActivity(intent);
Click to expand...
Click to collapse
Hey, thanks for the quick reply! That works wonders! Half way already. Thanks a lot.
Now how would I go about having it so that the apps I select in the list of apps stay selected, then upon an onClick of a button they get returned to my fragment (activity)? And to have them saved after that, would I need to read up on sqlite?
Hi there
I'm working on an application for light controll. I start a TabActivity with 2 childs tab "A" and tab "B". in the "onCreateOptionsMenu()" of the TabActivity I am creating the menu for the activitys.
How can I make, that the Activity in tab "A" reacts on clickt on the menu buttons?
I tryed out everything but nothing worked. Im searching at least since 15h.
Greez LoXeras
LoXeras said:
Hi there
I'm working on an application for light controll. I start a TabActivity with 2 childs tab "A" and tab "B". in the "onCreateOptionsMenu()" of the TabActivity I am creating the menu for the activitys.
How can I make, that the Activity in tab "A" reacts on clickt on the menu buttons?
I tryed out everything but nothing worked. Im searching at least since 15h.
Greez LoXeras
Click to expand...
Click to collapse
Something like this question? You need to override onPrepareOptionsMenu for different menus based on what tab is currently active. Then, in the onOptionsItemSelected just pass the selected item to the specific tab.
SimplicityApks said:
Something like this question? You need to override onPrepareOptionsMenu for different menus based on what tab is currently active. Then, in the onOptionsItemSelected just pass the selected item to the specific tab.
Click to expand...
Click to collapse
Thanks for the answere. This is what I tried. but I get crashes every time. A NullPointerException occurs every time. And if I try to select the hitten items in menu with the menu button it crasshes instantly.
Source:
Code:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle presses on the action bar items
command co = new command();
switch (item.getItemId()) {
case R.id.action_load:
co.LoadFile();
return true;
case R.id.action_clear:
co.clearlist();
return true; case R.id.action_save:
co.SaveFile();
return true;
case R.id.action_as:
co.AutoScroll();
return true;
case R.id.action_info:
co.showInfo();
return true;
default:
return super.onOptionsItemSelected(item); //Return selected item
}