switch state is not stable in listview when scrolling - java

I'am new to android and i use sample for my listview. because of that i can't change the code. i have one switch button in each item of my Listview. when i scroll the Listview switches change state randomly. how can i make switch state stable?
my listview class adapter:
public class MyCustomCursorAdapter extends CursorAdapter {
LIGHTS calling_activity;
private DatabaseHelper dbHelper;
public MyCustomCursorAdapter(Context context, Cursor c) {
super(context, c, 0);
this.calling_activity = (LIGHTS) context;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
return view;
}
#Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.adapter,parent,false);
}
#Override
public void bindView(final View view, Context context, Cursor cursor) {
((TextView)view.findViewById(R.id.id)).setText(cursor.getString(cursor.getColumnIndex(dbHelper._ID)));
((TextView)view.findViewById(R.id.KEYCODE)).setText(cursor.getString(cursor.getColumnIndex(dbHelper.TITLE)));
((TextView)view.findViewById(R.id.NAME)).setText(cursor.getString(cursor.getColumnIndex(dbHelper.DESC)));
ImageView option = view.findViewById(R.id.itemoption);
Switch thisswitch = view.findViewById(R.id.onoff);
thisswitch.setTag(cursor.getString(cursor.getColumnIndex(dbHelper._ID)));
thisswitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { calling_activity.myOnCheckedChangedHandler((String)buttonView.getTag(),isChecked);
}
});
option.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView itemID = (TextView) view.findViewById(R.id.id);
TextView itemTitle = (TextView) view.findViewById(R.id.KEYCODE);
TextView itemDesc = (TextView) view.findViewById(R.id.NAME);
String myId = itemID.getText().toString();
String myTitle = itemTitle.getText().toString();
String myDesc = itemDesc.getText().toString();
Intent intent = new Intent(calling_activity, ModifyActivity.class);
intent.putExtra("Id", myId);
intent.putExtra("Title", myTitle);
intent.putExtra("Desc", myDesc);
calling_activity.startActivity(intent);
}
});
}
}
and in my Lights activity :
#Override
public void myOnCheckedChangedHandler(String id, boolean check_status) {
Toast.makeText(
this,
"You changed the status for the row with an id of " + id +
" the status is now " + new Boolean(check_status).toString(),
Toast.LENGTH_SHORT).show();
String name = cursor.getString(cursor.getColumnIndex(dbHelper.DESC));
if(new Boolean(check_status).toString().equals("true")){
Toast.makeText(this,name +" is ON", Toast.LENGTH_SHORT).show();
}
}

Please manage through if/else case inside bindView at adapter, You need to check the switch condition like below :
// set the code into bind
if(switchCondition1 == 1)
{
//set the code as per condition wise
}else{
//
}
After change the state you also need to change the state into your list item and use notifydatasetChanged() method to refresh the list items.

Related

Item highlight not behaving as expected

I'm experiencing a strange behavior with a horizontal scroll bar that I made with RecyclerView,
Hint:
I use SharedPreferences in onItemClick interface to transfer the position of clicked item to the fragment where I set the adapter , then I use another interface to transfer the clicked item position from the fragment to the activity where I set current item via viewpager.
Current behavior:
Issue #1
when an item gets selected the background (highlight) color is not changing, it has to be clicked again to get the highlight color.
Issue #2
When an item is clicked the scroll state resets to 1
Question :
why is this happening? and how to fix it?
Expected behavior
when an item is clicked I want the following behavior (single item selection)
RecyclerView adapter class
public class PlanetAdapter extends RecyclerView.Adapter<PlanetAdapter.PlanetViewHolder> {
public interface OnItemClickListener {
void onItemClick(PlanetModel item);
}
private ArrayList<PlanetModel> episodeslist;
private OnItemClickListener listener;
SharedPreferences getPref1x1 = getContext().getSharedPreferences("PlanetAdapter", Context.MODE_PRIVATE);
int pos1x1 = getPref1x1.getInt("position",0);
int isPlanetSelected=pos1x1;
public PlanetAdapter(ArrayList<PlanetModel> episodeslist, OnItemClickListener listener) {
this.episodeslist = episodeslist;
this.listener = listener;
}
#Override
public PlanetAdapter.PlanetViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v= LayoutInflater.from(parent.getContext()).inflate(R.layout.planet_row, parent,false);
PlanetViewHolder vh=new PlanetViewHolder(v);
return vh;
}
#Override
public void onBindViewHolder(PlanetAdapter.PlanetViewHolder vh, int position) {
TextView tv = (TextView) vh.itemView;
tv.setText(episodeslist.get(position).getPlanetName());
tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.bg, 0, 0, 0);
vh.bind(episodeslist.get(position), listener);
if (episodeslist.get(position).isPlanetSelected()) {
vh.itemView.setBackgroundColor(getContext().getResources().getColor(R.color.colorPrimaryDark));
}else{
vh.itemView.setBackgroundColor(getContext().getResources().getColor(R.color.colorPrimaryLight));
}
//holder.image.setImageResource(R.drawable.planetimage);
//vh.text.setText(episodeslist.get(position).toString());
}
#Override
public int getItemCount() {
return episodeslist.size();
}
public class PlanetViewHolder extends RecyclerView.ViewHolder{
protected TextView text;
public PlanetViewHolder(View itemView) {
super(itemView);
text= (TextView) itemView.findViewById(R.id.text_id);
}
public void bind(final PlanetModel item, final OnItemClickListener listener) {
itemView.setOnClickListener(new View.OnClickListener() {
#Override public void onClick(View v) {
int position = getPosition();
int previousItem = isPlanetSelected;
isPlanetSelected = position;
notifyItemChanged(previousItem);
notifyItemChanged(position);
SharedPreferences setPref = v.getContext().getSharedPreferences("PlanetAdapter", Context.MODE_PRIVATE);
setPref.edit().putInt("position", position).apply ();
listener.onItemClick(item);
//Toast.makeText(getContext(), "You have clicked " + item, Toast.LENGTH_SHORT).show();
//Toast.makeText(getContext(), "You have clicked " + ((TextView) itemView).getText(), Toast.LENGTH_SHORT).show();
}
});
}
}
}
The SharedPreference has a wrong-stored position value. To get the correct position within the ViewHolder, you need to use getBindingAdapterPosition() instead of getPosition.
Also you should update the value of the item before using listener.onItemClick(item);
Also you need to toggle the value of the selection boolean on the object before using notifyItemChanged() in order to reflect the change.
itemView.setOnClickListener(new View.OnClickListener() {
#Override public void onClick(View v) {
int position = getBindingAdapterPosition();
int previousItem = selectedPosition;
selectedPosition = position;
// Updating the selector boolean before notifying the changes to the adapter
PlanetModel currentSelectedItem = episodeslist.get(position);
currentSelectedItem.setPlanetSelected(true);
PlanetModel previousSelectedItem = episodeslist.get(previousItem);
previousSelectedItem.setPlanetSelected(false);
// Notify the changes to the adapter
notifyItemChanged(previousItem);
notifyItemChanged(position);
SharedPreferences setPref = v.getContext().getSharedPreferences("PlanetAdapter", Context.MODE_PRIVATE);
setPref.edit().putInt("position", position).apply ();
// Here you should define `item` before triggering the interface callback.
listener.onItemClick(item);
}
});
UPDATE:
The click listener should not be in the bind() as this is called from onBindViewHolder, you are iterating many listeners while you should only need one, to fix this, you need to transfer that to the holder constructor:
So, change the onBindViewHolder to:
#Override
public void onBindViewHolder(PlanetAdapter.PlanetViewHolder vh, int position) {
TextView tv = (TextView) vh.itemView;
tv.setText(episodeslist.get(position));
tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.bg, 0, 0, 0);
// setting the highlight color
if (episodeslist.get(position).isPlanetSelected()) {
vh.itemView.setBackgroundColor(getContext().getResources().getColor(R.color.colorPrimaryLight));
} else {
vh.itemView.setBackgroundColor(getContext().getResources().getColor(R.color.colorPrimaryDark));
}
}
And change the ViewHolder to:
public class PlanetViewHolder extends RecyclerView.ViewHolder{
protected TextView text;
public PlanetViewHolder(View itemView) {
super(itemView);
text= (TextView) itemView.findViewById(R.id.text_id);
itemView.setOnClickListener(new View.OnClickListener() {
#Override public void onClick(View v) {
int position = getAdapterPosition();
int previousItem = selectedPosition;
selectedPosition = position;
// Updating the selector boolean before notifying the changes to the adapter
PlanetModel currentSelectedItem = episodeslist.get(position);
currentSelectedItem.setPlanetSelected(true);
PlanetModel previousSelectedItem = episodeslist.get(previousItem);
previousSelectedItem.setPlanetSelected(false);
// Notify the changes to the adapter
notifyItemChanged(previousItem);
notifyItemChanged(position);
SharedPreferences setPref = v.getContext().getSharedPreferences("PlanetAdapter", Context.MODE_PRIVATE);
setPref.edit().putInt("position", position).apply ();
// Here you should define `item` before triggering the interface callback.
String item = episodeslist.get(position);
listener.onItemClick(item);
}
});
}
}

Checkbox and sharedPreferences

I am using a grid view for a movie app. When the user clicks on a movie, details of the movie are revealed. Inside this new activity, the user can mark the movie as favorite. I'm using sharedPreferences to store the state of the checkbox when checked or unchecked. The problem is that, when i go back to the grid view to choose another movie to mark it as favorite, all the movies in the grid view show marked as favorite even though i did not explicitly check these movies. Please, what could be responsible for this behavior? Below is my detail activity code:
public class MovieDetails extends AppCompatActivity {
private static final String SHARED_PF_NAME = "movieSP";
private static final String CHECK_BOX_STATE = "check_state";
private SharedPreferences sharedPreferences;
CheckBox checkBox;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_details);
getSupportActionBar().setTitle("Movie Details");
/*//get values passed from main
movie = getIntent().getParcelableExtra(MainActivity.MOVIE_IN_CURRENT_CLICKED_POSITION);
// get movie id of the movie that was just passed
final int movieIdOfMovieInCurrentlyClicked= movie.getMovieid();
//get path for trailer and reviews
String movieVideoPath = "https://api.themoviedb.org/3/movie/" + movieIdOfMovieInCurrentlyClicked+ "/videos?api_key=" + MovieDataSource.API_KEY;
String movieReviewPath = "https://api.themoviedb.org/3/movie/" + movieIdOfMovieInCurrentlyClicked + "/reviews?api_key=" + MovieDataSource.API_KEY;
// initiate asynctask
new MovieTrailerAsyncTask().execute(movieVideoPath);
new MovieReviewAsyncTask().execute(movieReviewPath);
// trailer recycler
trailerRecyclerview = findViewById(R.id.trailers_RecyclerView);
trailerRecyclerview.setHasFixedSize(true);
trailerRecyclerview.setLayoutManager(trailerLinearLayoutManager);
movieTrailerRecyclerViewAdapter = new MovieTrailerRecyclerViewAdapter(MovieDetails.this, movieTrailerArrayList);
trailerRecyclerview.setAdapter(movieTrailerRecyclerViewAdapter);
//reviews recycler
reviewRecyclerView = findViewById(R.id.reviews_recyclerview);
trailerRecyclerview.setHasFixedSize(true);
reviewRecyclerView.setLayoutManager(reviewLinearLayoutManager);
movieReviewRecyclerViewAdapter = new MovieReviewRecyclerViewAdapter(MovieDetails.this, movieReviewsArrayList);
reviewRecyclerView.setAdapter(movieReviewRecyclerViewAdapter);
TextView movieTitleTextView = findViewById(R.id.movieTitle);
ImageView movieImageView = findViewById(R.id.movieImage);
TextView movieReleaseDateView = findViewById(R.id.movieReleaseDate);
TextView movieRatingView = findViewById(R.id.movieRating);
TextView movieDescriptionView = findViewById(R.id.movieDescription);
Picasso.with(this)
.load(movie.getMovieImagePath())
.fit()
.placeholder(R.drawable.progress_file)
.error(R.drawable.ic_launcher_background)
.into(movieImageView);
movieTitleTextView.setText(movie.getMovieTitle());
movieReleaseDateView.setText(movie.getMovieReleaseDate());
movieRatingView.setText(String.format("%s%s", String.valueOf(movie.getMovieRating()), ratingDenominator));
movieDescriptionView.setText(movie.getMovieDescripton());
*/
checkBox= findViewById(R.id.checkbox_button);
sharedPreferences = getSharedPreferences(SHARED_PF_NAME, Context.MODE_PRIVATE);
checkBox.setChecked(sharedPreferences.getBoolean(CHECK_BOX_STATE, false));
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
sharedPreferences.edit().putBoolean(CHECK_BOX_STATE, isChecked).apply();
if (isChecked){
Toast.makeText(getApplicationContext(), "checked",
Toast.LENGTH_LONG).show();
}else {
Toast.makeText(getApplicationContext(), "not checked",
Toast.LENGTH_LONG).show();
}
}
});
}
Grid view Adapter:
public class MovieDisplayAdapter extends BaseAdapter {
private Context context;
private ArrayList<Movie> movies;
MovieDisplayAdapter(Context context,ArrayList<Movie> movies) {
this.context = context;
this.movies = movies;
}
#Override
public int getCount() {
Log.i("count",String.valueOf(movies.size()));
return movies.size();
}
#Override
public Object getItem(int position) {
return movies.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
class ViewHolder {
ImageView imageView;
ViewHolder(View view) {
imageView = view.findViewById(R.id.imageView);
}
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = LayoutInflater.from(context);
if (convertView == null) {
convertView = inflater.inflate(R.layout.single_row, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else
{
holder = (ViewHolder) convertView.getTag();
}
Picasso.with(context)
.load(movies.get(position).getMovieImagePath())
.placeholder(R.drawable.progress_file)
.fit()
.error(R.drawable.ic_launcher_background)
.centerCrop()
.into(holder.imageView); // View where image is loaded.
return convertView;
}
}
MainActivity(intent code):
gridView.setAdapter(new MovieDisplayAdapter(MainActivity.this, movies));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
movieIdOfMovieInCurrentlyClicked = movies.get(position).getMovieid();
moviePosition = position;
Intent intent = new Intent(MainActivity.this, MovieDetails.class);
//When clicked, the position of the current movie
Movie movieIncurrentClickedPosition = movies.get(moviePosition);
intent.putExtra(MOVIE_IN_CURRENT_CLICKED_POSITION, movieIncurrentClickedPosition);
startActivity(intent);
}
});
}
You are using a single variable (CHECK_BOX_STATE) to store the favorite status of all the movies, rather than storing the favorite status for each movie. You need to create a different boolean entry in the SharedPreferences for each favourite movie, and then remove it when the movie is no longer favourite.
public class MovieDetails extends AppCompatActivity {
private static final String SHARED_PF_NAME = "favoriteMovies";
private Movie movie; // I'm guessing the class name is Movie
private CheckBox checkBox;
private SharedPreferences sharedPreferences;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_details);
getSupportActionBar().setTitle("Movie Details");
movie = getIntent().getParcelableExtra(
MainActivity.MOVIE_IN_CURRENT_CLICKED_POSITION);
final String key = Integer.toString(movie.getMovieId());
// all the other stuff...
sharedPreferences = getSharedPreferences(SHARED_PF_NAME, Context.MODE_PRIVATE);
checkBox = findViewById(R.id.checkbox_button);
checkBox.setChecked(sharedPreferences.getBoolean(key, false));
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked){
sharedPreferences.edit().putBoolean(key, true).apply();
Toast.makeText(getApplicationContext(), "checked",
Toast.LENGTH_LONG).show();
} else {
sharedPreferences.edit().remove(key).apply();
Toast.makeText(getApplicationContext(), "not checked",
Toast.LENGTH_LONG).show();
}
}
});
}
}
the thing here is that you are saving a single check state, so when you try to retrieve that checkstate is just one, you have to filter each of the checkStates by an identifier for each of the movies...
as an additional comment is better to store that information in the movies object in a local database so you just do a simple query to update and retrieve that state

update the text of a listView row

I want my listView to be updated after clicking on a row (or any event, but let's focus on click).
I did something, but it updates more than one row (maybe it updates the first visible row and the one after the last visible...).
Here is the full code
Activity code
DatabaseHandler colisageBase;
ListView listView;
List<Site> sites;
String id_tournee;
SiteAdapter siteAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_site_choice);
Intent intent = getIntent();
id_tournee = intent.getStringExtra("idTourneeSelectionnee");
this.listView = findViewById(R.id.list_view_site);
this.colisageBase = new DatabaseHandler(this);
sites = colisageBase.selectAllSite(id_tournee);
siteAdapter = new SiteAdapter(SiteChoiceActivity.this, sites);
listView.setAdapter(siteAdapter);
colisageBase.closeDB();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Site selectedSite = sites.get(position);
selectedSite.setIsBarred(true);
sites.set(position, selectedSite);
siteAdapter.notifyDataSetChanged();
//goToOperationActivity(selectedSite.SiteOut());
}
});
Adapter code
public class SiteAdapter extends ArrayAdapter<Site> {
public SiteAdapter(Context context, List<Site> sites) {
super(context, 0, sites);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_site,parent, false);
}
SiteViewHolder viewHolder = (SiteViewHolder) convertView.getTag();
if(viewHolder == null){
viewHolder = new SiteViewHolder();
viewHolder.heure_supposee = convertView.findViewById(R.id.heure_supposee);
viewHolder.libelle_site = convertView.findViewById(R.id.libelle_site);
viewHolder.logo_telephone = convertView.findViewById(R.id.logo_phone);
convertView.setTag(viewHolder);
}
Site site = getItem(position);
viewHolder.heure_supposee.setText(site.getHeure_supposee());
viewHolder.libelle_site.setText(site.getLibelle_site());
viewHolder.logo_telephone.setVisibility(View.INVISIBLE);
if (site.getSur_appel().equals("O")) viewHolder.logo_telephone.setVisibility(View.VISIBLE);
if (site.isBarred()) viewHolder.libelle_site.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
return convertView;
}
#Override
public void notifyDataSetChanged()
{
super.notifyDataSetChanged();
}
private class SiteViewHolder{
public TextView heure_supposee;
public TextView libelle_site;
public ImageView logo_telephone;
}
}
Please suggest what's wrong with the code.
The answer was given in the comments by I_A_Mok, but i have to add more details:
In the case of a cell, when you do an action in an "if" condition , you usually have to do the opposite in an "else" condition.
In my case, after my condition where I strike through text, I had to add an else condition where I don't strike through text.
if (site.isBarred()){
viewHolder.libelle_site.setPaintFlags(viewHolder.libelle_site.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}else {
viewHolder.libelle_site.setPaintFlags(viewHolder.libelle_site.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG));
}

Making Object from getItem() and accessing the fields

I have a list listview in my code that contains 2 buttons and 2 TextViews. I want to access the text of each textView by Clicking on buttons. here is the code of the adapter...
public class TracksAdapter extends SimpleAdapter {
public TracksAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final TracksAdapter proxy = this;
final View trackView = super.getView(position, convertView, parent);
Button dl = (Button) trackView.findViewById(R.id.dl);
dl.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Do something with data : proxy.getItem(position)
TextView tv = (TextView) trackView.findViewById(R.id.track);
String track = tv.getText().toString();
Toast.makeText(getApplicationContext() , track , Toast.LENGTH_LONG);
}
});
Button play = (Button) trackView.findViewById(R.id.play);
play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Do something with data : proxy.getItem(position)
Toast.makeText(getApplicationContext() , String.valueOf(proxy.getItem(position)).indexOf("file=") , Toast.LENGTH_LONG);
}
});
return trackView;
}
}
the result of proxy.getItem(position) is something like {id=4 , name=foo , track=fofoo}
what should I do to access 'foo' ????
Try his code to get the text from onClick:
TextView tv = (TextView) parent.findViewById(R.id.your_textView_position_id_from_xml);
String s = tv.getText().toString();

Get Selected value from Spinner inside ListView Android

I have a ListView of Spinners I'm trying to get the selected values out of. Some of the Spinners have the first selection automatically selected if there is only 1 item in the list, so I feel
setOnItemSelectedListener
won't necessarily work? Either way, I'm unsure how to code this scenario. Even if I had the listener coded correctly, How do I use it in my class to work with the adapter?
CustomAdapter
public class CustomPLNViewAdapter extends BaseAdapter{
private static ArrayList<ArrayList<String>> partLotNumbersArrayList;
private static ArrayList<String> partNames;
private LayoutInflater mInflater;
private Context myContext;
public CustomPLNViewAdapter(Context context, ArrayList<ArrayList<String>> results, ArrayList<String> parts){
partLotNumbersArrayList = results;
partNames = parts;
mInflater = LayoutInflater.from(context);
myContext = context;
}
#Override
public int getCount() {
return partLotNumbersArrayList.size();
}
#Override
public Object getItem(int position) {
return partLotNumbersArrayList.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.view_assembly_parts, null);
holder = new ViewHolder();
holder.txtName = (TextView) convertView.findViewById(R.id.partName);
holder.spinner = (Spinner) convertView.findViewById(R.id.LotNumbers);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtName.setText(partNames.get(position));
ArrayAdapter<String> adp1=new ArrayAdapter<String>(myContext, android.R.layout.simple_list_item_1, partLotNumbersArrayList.get(position));
adp1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//set the adapter to the spinnner
holder.spinner.setAdapter(adp1);
//if there is only one other part besides "" then set that as default part
if(partLotNumbersArrayList.get(position).size() == 2){
holder.spinner.setSelection(1);
}
return convertView;
}
static class ViewHolder {
TextView txtName;
Spinner spinner;
}
}
Where I am calling the code. Obviously I get an error here because an ArrayList cannot be cast to Spinner, but I'm unsure how to get the View of the Adapter and then the subsequent spinner?
// save button click event
saveButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Log.d("lv count", Integer.toString(lv.getCount()));
//iterate through listview,
for(int i = 0; i < lv.getCount(); i++){
Spinner temp = (Spinner) lv.getItemAtPosition(i);
Log.d("lv isItemCheck", temp.getSelectedItem().toString());
}
//check to make sure all items have been selected
if(!checkAllParts()){
Toast.makeText(getApplicationContext(), "Please Select All List Items", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(), "All items have been selected", Toast.LENGTH_SHORT).show();
}
//go back to previous intent, return 100 that saving succeeded
//close intent
}
});

Categories

Resources