Order_Content
- this is the page I want to show the nested listview. Here I Take input for The Header Data And Child Data from JSON Webservice. String res for Dropdown menu and All remaining Stings mov ,movpks, mus, muspks for listview.
When I click on MOVIE Then Show Zindagi melena dubara... all but when I click on Zindagi mile na dubara I want add "order" to each childlistview.
public class Order_Content extends Activity{
Spinner selectpkj;
EditText Year,Banner,Producer,Director,Main_Cast,Genre,Music_Director;
Button Search;
/*String[] res = new String[] { "Movie", "Movie Packs", "Music",
"Music Packs", "All" };*/
String res;
String mov;
String movpks;
String mus;
String muspks;
String Yeard,Bannerd,Producerd,Directord,Maisn_Castd,Genred,Music_Directord;
//Deifine the all variable for the expandable platform **//
ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.order_content);
//*** Bind All Definer Layouts ***//
selectpkj=(Spinner)findViewById(R.id.spselectmovie);
Search =(Button)findViewById(R.id.serach);
Year=(EditText)findViewById(R.id.year);
Banner=(EditText)findViewById(R.id.banner);
Producer=(EditText)findViewById(R.id.producer);
Director=(EditText)findViewById(R.id.director);
Main_Cast=(EditText)findViewById(R.id.maincast);
Genre=(EditText)findViewById(R.id.genere);
Music_Director=(EditText)findViewById(R.id.musicdirector);
//*** Get EditText Value for search here ***//
/*Yeard = Year.getText().toString();
Bannerd = Banner.getText().toString();
Producerd = Producer.getText().toString();
Directord = Director.getText().toString();
Maisn_Castd = Main_Cast.getText().toString();
Genred = Genre.getText().toString();
Music_Directord = Music_Director.getText().toString();
*/
// *** Getting Contents form the last pages ***//
String lcouserID = getIntent().getStringExtra("lcouserID");
String SearchList = getIntent().getStringExtra("SearchList");
String MOVIES = getIntent().getStringExtra("MOVIES");
String MOVIESPACK = getIntent().getStringExtra("MOVIESPACK");
String MUSIC = getIntent().getStringExtra("MUSIC");
String MUSICPACK = getIntent().getStringExtra("MUSICPACK");
res = SearchList;
mov = MOVIES;
movpks = MOVIESPACK;
mus = MUSIC;
muspks = MUSICPACK;
// get the listview
expListView = (ExpandableListView) findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
// Listview Group click listener
expListView.setOnGroupClickListener(new OnGroupClickListener() {
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// Toast.makeText(getApplicationContext(),
// "Group Clicked " + listDataHeader.get(groupPosition),
// Toast.LENGTH_SHORT).show();
return false;
}
});
// Listview Group expanded listener
expListView.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Expanded",
Toast.LENGTH_SHORT).show();
}
});
// Listview Group collasped listener
expListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int groupPosition) {
Toast.makeText(getApplicationContext(),
listDataHeader.get(groupPosition) + " Collapsed",
Toast.LENGTH_SHORT).show();
}
});
// Listview on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),listDataHeader.get(groupPosition)+ " : "+ listDataChild.get(listDataHeader.get(groupPosition)).get(childPosition), Toast.LENGTH_SHORT).show();
return false;
}
});
// *** Display Data into Spinner Successfully ***//
final List<String> list = new ArrayList<String>();
try {
JSONArray array = new JSONArray(res.toString());
// JSONArray array = new JSONArray(res.toString());
for (int i = 0; i < array.length(); i++) {
list.add(array.getString(i));
System.out.println("I Position : " + array.getString(i));
// System.out.println("List Output : " + list);
}
} catch (Exception e) {
e.printStackTrace();
}
String myString = "Select to Search";
String addatend ="All";
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter.notifyDataSetChanged();
//dataAdapter.addAll(myString);
dataAdapter.insert(myString, 0);
dataAdapter.add(addatend);
selectpkj.setAdapter(dataAdapter);
selectpkj.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
// TODO Auto-generated method stub
Object item = parent.getItemAtPosition(position);
if (item.equals("Select to Search")){
invisible();
//Subscriber_Name.setText(null);
}else if (item.equals("MOVIE") || (item.equals("All"))) {
visible();
}else{
invisible();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});
}
//*** Preparing the list data method ***//
private void prepareListData() {
// TODO Auto-generated method stub
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
//*** Here logic for the add data in to MAIN LIST from response ***//
final List<String> list1 = new ArrayList<String>();
try {
JSONArray array = new JSONArray(res.toString());
// JSONArray array = new JSONArray(res.toString());
for (int i = 0; i < array.length(); i++) {
list1.add(array.getString(i));
System.out.println("I Position : " + array.getString(i));
// System.out.println("List Output : " + list);
}
} catch (Exception e) {
e.printStackTrace();
}
listDataHeader = list1;
/*// Adding child data
listDataHeader.add("Movie");
listDataHeader.add("Movie Packs");
listDataHeader.add("Music");
listDataHeader.add("Music Packs");*/
//*** Here logic for the add data in to MAIN LIST from response ***//
final List<String> movi = new ArrayList<String>();
try {
JSONArray array = new JSONArray(mov.toString());
// JSONArray array = new JSONArray(res.toString());
for (int i = 0; i < array.length(); i++) {
movi.add(array.getString(i));
System.out.println("I Position : " + array.getString(i));
// System.out.println("List Output : " + list);
}
} catch (Exception e) {
e.printStackTrace();
}
// Adding child data
List<String> top250 = new ArrayList<String>();
top250 = movi;
/* top250.add("The Shawshank Redemption");
top250.add("The Godfather");
top250.add("The Godfather: Part II");
top250.add("Pulp Fiction");
top250.add("The Good, the Bad and the Ugly");
top250.add("The Dark Knight");
top250.add("12 Angry Men");*/
final List<String> movipacks = new ArrayList<String>();
try {
JSONArray array = new JSONArray(movpks.toString());
// JSONArray array = new JSONArray(res.toString());
for (int i = 0; i < array.length(); i++) {
movipacks.add(array.getString(i));
System.out.println("I Position : " + array.getString(i));
// System.out.println("List Output : " + list);
}
} catch (Exception e) {
e.printStackTrace();
}
List<String> nowShowing = new ArrayList<String>();
nowShowing = movipacks;
/*nowShowing.add("The Conjuring");
nowShowing.add("Despicable Me 2");
nowShowing.add("Turbo");
nowShowing.add("Grown Ups 2");
nowShowing.add("Red 2");
nowShowing.add("The Wolverine");*/
final List<String> musi = new ArrayList<String>();
try {
JSONArray array = new JSONArray(mus.toString());
// JSONArray array = new JSONArray(res.toString());
for (int i = 0; i < array.length(); i++) {
musi.add(array.getString(i));
System.out.println("I Position : " + array.getString(i));
// System.out.println("List Output : " + list);
}
} catch (Exception e) {
e.printStackTrace();
}
List<String> comingSoon = new ArrayList<String>();
comingSoon = musi;
/*comingSoon.add("2 Guns");
comingSoon.add("The Smurfs 2");
comingSoon.add("The Spectacular Now");
comingSoon.add("The Canyons");
comingSoon.add("Europa Report");*/
final List<String> musipks = new ArrayList<String>();
try {
JSONArray array = new JSONArray(muspks.toString());
// JSONArray array = new JSONArray(res.toString());
for (int i = 0; i < array.length(); i++) {
musipks.add(array.getString(i));
System.out.println("I Position : " + array.getString(i));
// System.out.println("List Output : " + list);
}
} catch (Exception e) {
e.printStackTrace();
}
List<String> musicpaks = new ArrayList<String>();
musicpaks = musipks;
/*musicpaks.add("2 Guns");
musicpaks.add("The Smurfs 2");
musicpaks.add("The Spectacular Now");
musicpaks.add("The Canyons");
musicpaks.add("Europa Report");*/
listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
listDataChild.put(listDataHeader.get(1), nowShowing);
listDataChild.put(listDataHeader.get(2), comingSoon);
listDataChild.put(listDataHeader.get(3), musicpaks);
}
//*** invisible method ***//
protected void invisible() {
// TODO Auto-generated method stub
Year.setVisibility(View.INVISIBLE);
Banner.setVisibility(View.INVISIBLE);
Producer.setVisibility(View.INVISIBLE);
Director.setVisibility(View.INVISIBLE);
Main_Cast.setVisibility(View.INVISIBLE);
Genre.setVisibility(View.INVISIBLE);
Music_Director.setVisibility(View.INVISIBLE);
}
//*** Visible Method ***//
public void visible() {
// TODO Auto-generated method stub
Year.setVisibility(View.VISIBLE);
Banner.setVisibility(View.VISIBLE);
Producer.setVisibility(View.VISIBLE);
Director.setVisibility(View.VISIBLE);
Main_Cast.setVisibility(View.VISIBLE);
Genre.setVisibility(View.VISIBLE);
Music_Director.setVisibility(View.VISIBLE);
getdata();
}
public void getdata() {
// TODO Auto-generated method stub
Yeard = Year.getText().toString();
Bannerd = Banner.getText().toString();
Producerd = Producer.getText().toString();
Directord = Director.getText().toString();
Maisn_Castd = Main_Cast.getText().toString();
Genred = Genre.getText().toString();
Music_Directord = Music_Director.getText().toString();
Search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//prepareListData();
}
});
}
}
If I am getting you right, than what you want is something like an
ExpandableListview
inside anotherExpandableListview
. The requirement is tricky and solution is bit complicated.Follow the bellow link. It demonstrates the 3-level expandable
ListView
.http://mylifewithandroid.blogspot.com/2011/02/3-level-expandable-lists.html
Mark as right, if this is what you are looking for. :)