in my app I am loading phone numbers from database to listview, this is done and work fine. Now I want when user click at any number in listview the app must dialing the selected number. How to get the list item value and make call directly when clicked.
String[] myArr = (String[])records.ToArray(typeof(string));
//setting array adapter with item layout
ArrayAdapter adapter = new ArrayAdapter(this, Resource.Layout.item, Resource.Id.itemTxt, (System.Collections.IList)records);
list.SetAdapter(adapter); // setting adapter to list view
list.ItemClick += List_ItemClick;
}
void List_ItemClick(object sender, AdapterView.ItemClickEventArgs e )
{
var uri = Android.Net.Uri.Parse("tel:" +???? );
var intent = new Intent(Intent.ActionDial, uri);
StartActivity(intent);
}
Related
I've tried this and it looks like majority of search results reference to Android studio. I'm using visual studio, xamarin forms.
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Main);
Spinner spinner = FindViewById<Spinner> (Resource.Id.spinner);
spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs> (spinner_ItemSelected);
var adapter = ArrayAdapter.CreateFromResource (
this, Resource.Array.my_array, Android.Resource.Layout.SimpleSpinnerItem);
adapter.SetDropDownViewResource (Android.Resource.Layout.SimpleSpinnerDropDownItem);
spinner.Adapter = adapter;
}
The spinner loads perfectly but the item selected method opens the activity on loading.
private void spinner_ItemSelected (object sender, AdapterView.ItemSelectedEventArgs e)
{
SetContentView (Resource.Layout.page1);
}
How best can I load the activity on specific item selection. Note: the items are referenced in the Strings.xml.
Because Spinner chooses the first item by default when initialized, it will fire spinner_ItemSelected
You can add a conditional judgment to your spinner_ItemSelected method:
private void spinner_ItemSelected (object sender, AdapterView.ItemSelectedEventArgs e)
{
var index = e.Parent.SelectedItemPosition; //base on the select position
var obj = e.Parent.SelectedItem; // base on the selectitem value(string)
// xxx is your conditions
if(index == xxx)
{
SetContentView (Resource.Layout.page1);
}
// or
if(obj.ToString().Equals("xxx"))
{
SetContentView (Resource.Layout.page1);
}
}
I use simple split view controller in my osx application... split item 0 is used for menu and second one is for content (like in slack application).
I get memory leak, so need optimizations ... here is what I do when menu item is clicked:
partial void SettingsClicked (NSObject sender)
{
HighLightMenuItem (SETTINGS_INDEX);
var svc = ParentViewController as NSSplitViewController;
SettingsVC = SettingsVC ?? Storyboard?.InstantiateControllerWithIdentifier ("settingsViewController") as SettingsViewController;
var svi = new NSSplitViewItem ();
svi.ViewController = SettingsVC;
DisableBack ();
svc.RemoveSplitViewItem (svc.SplitViewItems [1]);
svc.InsertSplitViewItem (svi, 1);
}
I have created a RecyclerView adapter and I'm trying to start an activity when a row is clicked:
public override OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
MyViewHolder viewHolder = (MyViewHolder)holder;
viewHolder.MyView.Click += (sender, e) =>
{
var context = viewHolder.MyView.Context;
var intent = new Intent(context, typeof(DetailActivity));
context.StartActivity(intent);
}
}
When I click the first row it will take me to the activity like I want. If I scroll down so that the first row is rebound and then scroll back to the top again and then click the first row then my Click event fires twice. Once for the first row that was bound and then again for a row that was bound when I scrolled.
Is there an event you need to handle to unregister the click events?
I believe the standard pattern is to setup your clickhandlers in the constructor of the ViewHolder. Then in OnBindViewHolder, you update the Views/Data inside the ViewHolder.
Something like this (not compiled code):
Adapter:
public override OnBindViewHolder()
{
MyViewHolder viewHolder = (MyViewHolder)holder;
viewHolder.SetData(whatever data you care about);
}
MyViewHolder:
public MyViewHolder(View view) : base(view)
{
MainView = view;
MainView.Click += (sender, e) =>
{
var context = MainView.Context;
var intent = new Intent(context, typeof(DetailActivity));
context.StartActivity(intent);
}
}
Doing it this way keeps the Adapter cleaner by putting business logic in the ViewHolder, and also prevents your click handlers from being constantly setup and torn down as you scroll.
I'm implementing a notification system using Xamarin platform, which extends to wearable devices to send the notification. I also want to get the input of user from the wear notification and i have programed it in such away that user can select text or use voice. i followed the following tutorial
http://developer.android.com/training/wearables/notifications/voice-input.html
my code is:
void SendWearNotification (string message, string from)
{
var valuesForActivity = new Bundle();
valuesForActivity.PutString ("message", message);
String groupkey = "group_key_emails";
var intent = new Intent (this, typeof(MyMainActivity));
intent.PutExtras (valuesForActivity);
intent.AddFlags (ActivityFlags.ClearTop);
var pendingIntent = PendingIntent.GetActivity (this, 0, intent, PendingIntentFlags.OneShot);
var builder = new NotificationCompat.Builder (this)
.SetAutoCancel (true)
.SetContentIntent (pendingIntent)
.SetContentTitle (from)
.SetSmallIcon (Resource.Drawable.Iconlogo)
.SetContentText (message) //message is the one recieved from the notification
.SetTicker(from)
.SetGroup (groupkey) //creates groups
.SetPriority((int)NotificationPriority.High);
//
//for viewing the message in second page
var pagestyle= new NotificationCompat.BigTextStyle();
pagestyle.SetBigContentTitle (from)
.BigText (messagefromapp); //message from app is the one rerieved from the wcf app
//second page
var secondpagenotification = new NotificationCompat.Builder (this)
.SetStyle (pagestyle)
.Build ();
//intent for voice input or text selection
var wear_intent = new Intent (Intent.ActionView);
var wear_pending_intent = PendingIntent.GetActivity (this,0,wear_intent,0);
// Create the reply action and add the remote input
setRemoteInput ();
var action = new NotificationCompat.Action.Builder (Resource.Drawable.ic_mes,
GetString (Resource.String.messages), wear_pending_intent)
.AddRemoteInput (remoteinput)
.Build ();
//add it to the notification builder
Notification notification = builder.Extend (new NotificationCompat.WearableExtender ()
.AddPage (secondpagenotification).AddAction(action)).Build ();
//create different notitfication id so that we can as list
if(notification_id<9){
notification_id += 1;
}else{
notification_id=0;
}
var notificationManager = (NotificationManager)GetSystemService(Context.NotificationService);
notificationManager.Notify (notification_id+2, notification);
}
this method is implmented inside GCMListnerService class.
According to the tutorial from the above link, i can retreive the input data user selected or spoke uing the following code:
private void getResponse(Intent intent){
Bundle remoteInput = RemoteInput.GetResultsFromIntent(intent);
if (remoteInput != null) {
Toast.MakeText(this, remoteInput.GetCharSequence(EXTRA_VOICE_REPLY), ToastLength.Short);
}
//return null;
}
My question is when do i call this method, how do i know if user have selected a text en send from the wearable device. if there is any event which i can use.
I got the solution. the method the gets the remote input (the "getresponse" in my case) should be called from the "Oncreate" method of an activity that is used when the notification is created. In my case the actvity i used is "MyMainActivity" when i create the intent of the notification as u can see it in the code. So this means the method will be called twice, when the application runs, and when user reponds from the wear. but ony in the second case will the "remoteinput.getResultfromIntent" will have a value. I hope it will help for someone with same issues.
I have a search form that opens in a com.smartgwt.client.widgets.Window.Window(). In it, I have a VLayout, in which I have a search form:
DynamicForm search = new DynamicForm();
// setMargin, setTitle, setNumCols
TextItem name = new TextItem();
name.setFormatOnFocusChange(true);
//setEditorValueFormatter, etc.
search.setFields(/*some fields*/, name, /*other fields*/);
name.focusInItem();
And the focus is not in the item (it's nowhere). Why is that so?
Thank you in advance!
EDIT:
Here is the code of the two Mediators:
public class MainMediator extends Mediator {
private Window popup = new Window();
protected void initView(){
// here I have a Form with fields and icon on one TextItem, on which I do:
searchField.addIconClickHandler(new IconClickHandler() {
popup = new Window();
popup.setIsModal(true);
popup.setShowModalMask(true);
});
}
public final void handleNotification(final INotification notification){
// if the right notification is sent, execute this code:
PopupMediator m = (PopupMediator) this.getFacade().retreiveMediator(PopupMediator.NAME);
VLayout popupLayout = (VLayout) m.getViewComponent();
popup.addItem(popupLayout);
popup.show();
}
}
public class PopupMediator extends Mediator {
protected void initView(){
viewComponent = new VLayout();
DynamicForm searchForm = new DynamicForm();
// searchForm props
TextItem name = new TextItem();
// name props and some other fields
searchForm.setFields(name /* and the others */);
VLayout searchFormContainer = new VLayout();
// searchFormContainer props
searchFormContainer.setMembers(seachForm);
name.focusInItem(); // not working on popup shown
HLayout searchContainer = new HLayout();
// searchContainer props
searchContainer.setMembers(grid1, searchFormContainer);
VLayout container = new VLayout();
// container props
container.setMembers (searchContainer, grid2);
((VLayout)viewComponent).setMembers(container, buttons);
}
You're getting this problem because formitem.focusInItem() works only after the formitem is drawn or say rendered in the browser. Adding the formitem in DynamicForm does not draw it.
I don't know where you're placing the DynamicForm, but to understand it completely, look at the following code:
Window window = new Window();
window.setSize("900px", "500px");
VLayout layout = new VLayout();
DynamicForm dynamicForm = new DynamicForm();
dynamicForm.setSize("800px", "400px");
TextItem item = new TextItem();
dynamicForm.setFields(item);
item.focusInItem(); // This won't work.
layout.addMember(dynamicForm);
window.addItem(layout);
item.focusInItem(); // This won't work.
window.show();
item.focusInItem(); // This will work.
So change your code accordingly.
Not sure how you receive handleNotification() callbacks, but you shouldn't use window.addItem() in it.
That will cause multiple items to be added/overwritten each time callback is called.
If handleNotification() callback is required, it should be only used for window.show(), plus any form field population/setting focus/etc.
If the content of Window is NOT going to change from one callback to another, initialize window layout during window creation.
If content of Window is GOING to change from one callback to another, you will need to remove previously added items.
Here's a simple working implementation that popup the window on a button click and set focus on a given field.
TextItem name1 = new TextItem("name1", "Name 1");
final TextItem name2 = new TextItem("name2", "Name 2"); // setting focus to name2
TextItem name3 = new TextItem("name3", "Name 3");
final DynamicForm searchForm = new DynamicForm();
// searchForm.setAutoFocus(true); // sets focus to first focusable field
searchForm.setFields(name1, name2, name3);
VLayout searchFormContainer = new VLayout();
searchFormContainer.setMembers(searchForm);
final Window window = new Window();
window.setIsModal(true);
window.setShowModalMask(true);
window.setAutoCenter(true);
window.setSize("400px", "300px");
window.addItem(searchFormContainer);
Button button = new Button("Search");
button.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
window.show();
name2.focusInItem();
// searchForm.focusInItem(name2); // this also works
}
});
Its possible to use DynamicForm.setAutoFocus to automatically focus on first focusable field in the form.
Why don't you try to focus on the form itself:
search.focus();