• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Custom Spinner

 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I need to create a country code picker beside my phone number in my app.  Behaviour would be: user selects country code a dialog opens with layout as country flag +country name+country code and when user selects for eg India  then it needs to be get reflected with India flag and it's country code right next to my phone number's textview. How to implement it After A lot of research got to know about spinner in android . My question is I should use spinner or any third party library.
 
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why third party library?  A spinner is a better solution as per your requirement.
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:Why third party library?  A spinner is a better solution as per your requirement.


I am not getting enough data how to use a spinner. . Can I set default value in a spinner based on location of user?
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course you can.  Though my suggestion would be to use a database, and populate spinner values from the underlying database.  Reason being in future when your data changes (modified/deleted/added) you don't have to change anything in the code, you will just manipulate the database table, and spinner will be populated based on those values.
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:Of course you can.  Though my suggestion would be to use a database, and populate spinner values from the underlying database.  Reason being in future when your data changes (modified/deleted/added) you don't have to change anything in the code, you will just manipulate the database table, and spinner will be populated based on those values.


Thanks for suggestion but currently I am just practicing how to use it

I am reading this tutorial Tutorial I have followed same steps. Now I am trying to edit this layout. I simply want to add a textview in custom layout.
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

priyanshi bhardwaj wrote:
I am reading this tutorial Tutorial I have followed same steps. Now I am trying to edit this layout. I simply want to add a textview in custom layout.



I am attaching some screen shots In picture 1 I simply want to only show it's country flag and country code and in picture 2 Select Country needs to come only once . How to  do this ?
Screenshot-2019-10-31-at-14.39.02.png
[Thumbnail for Screenshot-2019-10-31-at-14.39.02.png]
Picture 1
Screenshot-2019-10-31-at-14.39.26.png
[Thumbnail for Screenshot-2019-10-31-at-14.39.26.png]
picture 2
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need to see your code what you have done?
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:Need to see your code what you have done?

Was trying to access location also .So my code is having code for that also i.e you need to segregate.

MainActivity.java



countryItem.java



countryAdapter.java


activity main.xml



country_row.xml

Here is the code
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And your problem is Select country is getting repeated?
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:And your problem is Select country is getting repeated?

Yes and in picture 1  also I need only India flag and it's countrycode. not the whole layout. I have no idea how to do it.
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Coming the first problem i.e. Select country is getting repeated is happening due to the following reason



The above is in your country_row.xml file.  So every time it inflates the row, this gets displayed.  You need to take it out from here and put it in activity_main.xml before the spinner.    

Now coming to your second problem you just want to display flag and country flag and code not the country name.



Let me know if this helps.
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:
Now coming to your second problem you just want to display flag and country flag and code not the country name.



Let me know if this helps.



It didn't helped because it removed name of the country from the spinner dialog also.  i.e. countryName is not visible in picture 2 also.


 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about the first problem, select country? Is it solved.  But probably I didn't understand your 2nd prob properly.  Take that line out, and tell us what exactly do you want?
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:
The above is in your country_row.xml file.  So every time it inflates the row, this gets displayed.  You need to take it out from here and put it in activity_main.xml before the spinner.    



Was able to figure out this problem but if I do as suggested by you it will give something like in the picture (attaching screenshot). But I want Select Country to appear once on the top of this dialog.

this picture is having output after implementing your both solution . I guess it didn't worked
Screenshot-2019-10-31-at-16.33.56.png
[Thumbnail for Screenshot-2019-10-31-at-16.33.56.png]
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show activity_main.xml
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem 1 : In the Picture 2 screenshot (attached before) I just need flag image +flag name +country code under heading Select Country Heading. (This layout I want in my spinner Dialog)
Problem 2 : In the Picture 1 I am getting complete layout which I have defined for my Spinner dialog Where as I simply want is When user select country then only country code and country flag appears in picture one.
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:Show activity_main.xml



 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the screen shot of activity_main.xml?  Do you see Select country here?
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:Can you show the screen shot of activity_main.xml?  Do you see Select country here?



Yes I see select country here

Was just able to solve my Problem One . Thanks for your Idea

But will be needing your help to solve Problem 2 i.e. Need to show Select Country in spinner Dialog
Screenshot-2019-10-31-at-17.04.33.png
[Thumbnail for Screenshot-2019-10-31-at-17.04.33.png]
Screenshot-2019-10-31-at-17.05.56.png
[Thumbnail for Screenshot-2019-10-31-at-17.05.56.png]
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did this work?
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:Did this work?

Yes it worked is there a way to customise the font and font size.
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

priyanshi bhardwaj wrote:

Swastik Dey wrote:Did this work?

Yes it worked is there a way to customise the font and font size.

If No then please tell me is there any other way with full control on layout of spinner dialog.
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Font size of what?  Dialog header or spinner data?
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

priyanshi bhardwaj wrote:

Swastik Dey wrote:Need to see your code what you have done?

Was trying to access location also .So my code is having code for that also i.e you need to segregate.

MainActivity.java



countryItem.java



countryAdapter.java


activity main.xml



country_row.xml

Here is the code



@Swastik I was trying to access location permission also . But I am getting problem with requestLocationUpdates method (line no 124). If you can look into it.  
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:Font size of what?  Dialog header or spinner data?

Dialog Header .
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's bit tricky, however what problem are you getting with location updates,
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:That's bit tricky, however what problem are you getting with location updates,

It is saying function cannot be resolved .
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean a compile time error?
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, probably I noticed the problem.  The last argument to the method is this. As per documentation last argument should be a reference of LocattonListener interface. So apart from extending AppCompatActivity you have to implement LocationListener interface and implement it's methods.
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:Ok, probably I noticed the problem.  The last argument to the method is this. As per documentation last argument should be a reference of LocattonListener interface. So apart from extending AppCompatActivity you have to implement LocationListener interface and implement it's methods.

Yes Ok will do it and then  let you know what happens
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:That's bit tricky, however what problem are you getting with location updates,

And any suggestions on customize header
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't think of anything right now, but should be doable, if not in an easy way , then by some tricky way.
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:Can't think of anything right now, but should be doable, if not in an easy way , then by some tricky way.

You have helped me a lot just do any trick if you can think of.
 
Swastik Dey
Rancher
Posts: 2140
15
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want the solution right now?
 
priyanshi bhardwaj
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swastik Dey wrote:You want the solution right now?

not now but as soon as possible . According to your convenience
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!