I am trying to compose a list with some items expandable and some single items. I wish to have it so that when either a single item or expandable list child is clicked, I can call an intent based on the text of the item.
I suppose expandable lists would work, but is there a way to set items in an expandable list so that they don't have the expandable list icon? Should I use something other than a string array?
What is the best way to do this?
Thanks
Below is my incomplete code, I would like to insert the items "Zone 1", "Zone 2", "Zone 3" between the items "Atlanta" and "Boston" or as a subset of Atlanta:
package test.lists.special;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class SpecialList extends ListActivity{
TextView toptext;
String[] items={"Atlanta", "Boston", "Chicago", "Dallas"};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
items));
toptext=(TextView)findViewById(R.id.toptext);
}
public void onListItemClick(ListView parent, View v, int position,
long id) {
Intent intent = new Intent();
if (parent.getItemAtPosition(position)=="Atlanta")
{
//THIS IS WHERE I WISH TO INSERT "ZONE 1", "ZONE 2", "ZONE 3"
//between Atlanta and Boston in the list
}
else if (parent.getItemAtPosition(position)=="Boston")
{
intent.setClass(this, test.lists.special.Boston.class);
startActivity(intent);
}
else if (parent.getItemAtPosition(position)=="Chicago")
{
intent.setClass(this, test.lists.special.Chicago.class);
startActivity(intent);
}
else if (parent.getItemAtPosition(position)=="Dallas")
{
intent.setClass(this, test.lists.special.Dallas.class);
startActivity(intent);
}
else if (parent.getItemAtPosition(position)=="Zone 1")
{
intent.setClass(this, test.lists.special.Atlanta.Zone1.class);
startActivity(intent);
}
else if (parent.getItemAtPosition(position)=="Zone 2")
{
intent.setClass(this, test.lists.special.Atlanta.Zone2.class);
startActivity(intent);
}
else if (parent.getItemAtPosition(position)=="Zone 3")
{
intent.setClass(this, test.lists.special.Atlanta.Zone3.class);
startActivity(intent);
}
}
}