• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

App Inventor Android Custom Listview doesn't Update on newer Android SDK 22+

I have a custom Listview consisting of cells that are a TextView and a Spinner.

Textview

Spinner

Textview

Spinner

Textview

Spinner

etc

The spinner should only show up when the item in the ListView is selected. So I created a method in my fragment:

ListViewAdapter mAdapter;

View rootView = inflater.inflate(R.layout.fragmenttabselection, container,
false);

list = (ListView) rootView.findViewById(R.id.listview);
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
list.setSelector(android.R.color.holo_blue_light);

mAdapter = new ListViewAdapter(getActivity());

list.setOnItemClickListener(new OnItemClickListener() {

@override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {



mAdapter.setSpinnerOn(position);

}

});

Then in ListViewAdapter.java the relevant code is:

@SuppressLint("UseSparseArrays")
private HashMap<Integer,Spinner> spinnerhash = new HashMap<Integer,Spinner>();

public View getView(int position, View convertView, ViewGroup parent) {

// Declare Variables

ViewHolder holder = null;
int type = getItemViewType(position);
System.out.println("getView " + position + " " + convertView + " type = "
+ type);
//if (convertView == null) {
holder = new ViewHolder();
switch (type) {
case TYPE_ITEM:
convertView = mInflater.inflate(R.layout.spinner_item, null);
//holder.textView =
(TableLayout)convertView.findViewById(R.id.table_layout);
holder.textView =
(TextView)convertView.findViewById(R.id.textView1);

Spinner spinner =
(Spinner)convertView.findViewById(R.id.spinner1);
ArrayList<String> selections = new ArrayList<String>
(selections_array);

ArrayAdapter<String> adapter = new ArrayAdapter<String>
(context, android.R.layout.simple_spinner_dropdown_item, selections);
spinner.setAdapter(adapter);
spinner.setVisibility(View.GONE);
spinner.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent,
View
view, int pos, long id) {


System.out.println("parent.getItemAtPosition(pos).toString()" +
parent.getItemAtPosition(pos).toString());
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
spinnerhash.put(position, spinner);
break;
}
}

public void setSpinnerOn(int position)
{
for(Map.Entry<Integer,Spinner> m:spinnerhash.entrySet()){

Spinner currentspinner = m.getValue();

int spinnersize = spinnerhash.get(position).getCount();

if(m.getKey() == position && (spinnersize != 0) && (spinnersize !=
1)) {
currentspinner.setVisibility(View.VISIBLE);
}
else {
currentspinner.setVisibility(View.GONE);
}

}

}

where I set the Spinner to show just for the item that is clicked and all other Spinners remain hidden. This works in Android 5.1 absolutely fine. But my target SDK is 26 and on my Samsung Galaxy S6 (Android 7.0) the Spinner just shows for the first item clicked then gets stuck open and I can't get any Spinner to show for any other item in the list.

To summarize the issue:

I am using a custom ListView that houses cells which contain both a TextView and a Spinner. All of the spinners should be hidden except for the item selected in the list. This implementation works fine on Android 5.1 but not on Android 7.0+. In Android 7.0+ once an item is selected and the spinner appears for that item, even if another item is selected the previous selection spinner still appears and the spinner doesn't appear for the current selection. Any ideas on how to fix this?
 
Back
Top Bottom