java


List view activity is not working properly in switch case inside spinner class


Here BookList.java is a spinner class which maintains two occurrences one is book and another author and both have their own list view class. Through switching cases inside OnItemSelected() method their intent is accessed. But the problem i'm facing is that the first list view applied intent which is for book can't be accessed but can access author intent. it would be helpful if anybody help me editing my code. Here goes the java file.
public class BookList extends Activity implements OnItemSelectedListener {
Spinner spinner;
//private static final String[]paths = {"Book", "Author"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_booklist);
TextView t =(TextView)findViewById(R.id.t1) ;
spinner = (Spinner)findViewById(R.id.spinner);
//ArrayAdapter<String>adapter = new ArrayAdapter<String>(BookList.this,
//android.R.layout.simple_spinner_item,paths);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.blist_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
adapter.notifyDataSetChanged();
spinner.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {
final Intent intent;
switch (position) {
case 1:
intent = new Intent(BookList.this, BookListView.class);
startActivity(intent);
break;
case 2:
intent = new Intent(BookList.this, BookListAuthorView.class);
startActivity(intent);
break;
}
}
public void onNothingSelected(AdapterView<?> arg0) {
Toast.makeText(this, "Please choose a field", Toast.LENGTH_SHORT).show();
}
}
the item positions starts from 0 not from 1 so use this
And so 0 position will automatically trigger first time you open your activity so create a spinner array something like this for spinner
String arr ={"select choice","book","author"};
switch (position) {
case 1:
intent = new Intent(BookList.this, BookListView.class);
startActivity(intent);
break;
case 2:
intent = new Intent(BookList.this, BookListAuthorView.class);
startActivity(intent);
break;
}
plus you don't have to call `adapter.notifyDataSetChanged();'

Related Links

Is there any rest testing tool which hosts the webservices and injects mocks in the facade layer?
I need to find specific strings within a whole server project which I don't have the whole source. What can I do?
The method Sleep(int) is undefined for the type new Runnable(){} in Android
How to verify memory leak in Java
How do you debug an external jar with eclipse that has byte code?
Using if/switch/for conditions in test case
JSF 2 Spring XRebel Huge session
How to webscrape Steam Marketplace using JSoup
PriorityQueue iterating only half the elements
Java H2 dynamically inserting data
Jersey Maven configuration
How can I use a DAO inside a Controller in Spring MVC?
svn:externals write dependant project at same level as main project not under it
Java SWT - shell's titlebar disappear when using SWT.V_SCROLL on shell
Hyperlink event type activated error
Java sort 4 arrays into 1 array

Categories

HOME
multithreading
client
omnet++
fluentd
heroku
drivers
plone
relay
bookshelf.js
packages
retrofit
onelogin
bs4
slurm
elasticsearch-hadoop
session-variables
quicklook
alignment
visual-studio-cordova
jsprit
graphlab
django-admin
text-rendering
xlsxwriter
abi
jquery-ajaxq
mps
dxf
javacv
filezilla
spring-mybatis
typo3-6.2.x
assistant
skia
stormpath
http-status-code-503
calibre
pim
phpfreechat
gammu
wpf-controls
host
devextreme
dartium
jquery-bootgrid
automake
pdf-reactor
ibpy
midl
outlook-api
cubic-spline
wso2carbon
network-flow
svmlight
colorama
pillow
spring-cache
bind9
account-kit
specrun
log4c
underscore.js-templating
livequery
asp.net5
two-factor-authentication
cloudbees
netmq
natvis
tarjans-algorithm
wyam
sframe
android-listview
arcanist
appfabric-cache
processmodel
web-controls
dereference
mdt
applescript-objc
terminfo
android-radiobutton
typeof
app42
cloud-connect
algebraic-data-types
jsctypes
blending
tws
android-hardware
sublist
viewswitcher
removeclass
subscript
adk
subgurim-maps
locationlistener
appendto
inotifycollectionchanged
oncheckedchanged
h.323
zend-translate
castle-monorail
premature-optimization
ugc
signal-handling

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App