I am trying to use the selection in one ListView to determine the list displayed in another ListView to four dimensions. For example the first list would be:
A, B, C
Then by selecting list A you'd get
1, 2, 3
and B would return.
4, 5, 6
If 1 were selected then
I, II, III.
Selecting 5 would return yet anther list so on and so forth. This would continue on to a forth and final list which ultimately would be the user's selection.
The final ListView, to start, will have about 380 different lists it could be. If selection A then 2 then XII then display the correct list. Presumably I could name the lists according to selection as A2XII then call the list by that name.
Currently, my theory is to set the first ListView then in the Listener make it INVISIBLE and make VISIBLE the next. Then use the previous selection to determine what list the Adapter uses.
So my question is: How do I take the selection from one list and have it determine the next list by name?
package org.wmu.LMWTA;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import org.wmu.LMWTA.R;
public class Frag_Form extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View V = (LinearLayout)inflater.inflate(R.layout.form_layout, container, false);
if (container == null) {
return null;
}
final ListView cityList = (ListView) V.findViewById(R.id.list_city);
final ListView cat = (ListView) V.findViewById(R.id.cat);
ArrayAdapter<CharSequence> cityAdapt = ArrayAdapter.createFromResource(getActivity(),
R.array.cities, android.R.layout.simple_spinner_dropdown_item);
ArrayAdapter<CharSequence> catAdapt = ArrayAdapter.createFromResource(getActivity(),
R.array.cat, android.R.layout.simple_spinner_dropdown_item);
//ArrayAdapter<CharSequence> catAdapt = ArrayAdapter.createFromResource(getActivity(),
// R.array.subCat, android.R.layout.simple_spinner_dropdown_item);
cat.setAdapter(catAdapt);
cat.setVisibility(View.GONE);
cityList.setAdapter(cityAdapt);
cityList.setOnItemClickListener( new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show toast
Toast.makeText(parent.getContext(),
(CharSequence) cityList.getItemAtPosition(position).toString().replaceAll("\\s+", ""), Toast.LENGTH_SHORT).show();
cityList.setVisibility(View.GONE);
cat.setVisibility(View.VISIBLE);
}
});
return V;
}
}
If there is a better way to do this I would be very grateful to know the answer. My first thought was to use Spinners but I run into the same problem without nesting 380 Switches inside of more Switches.