如何在单击时将String Value设置为ExpandableListView Childs文本?

时间:2012-05-24 17:06:52

标签: java android eclipse expandablelistview

得到了一个很好的解释,这可能对任何想要做同样事情的人都有用!!!

   public class ExpList extends ExpandableListActivity
{
 String gametype;

  // strings for group elements

    static final String arrGroupelements[] = 
    {
   "POKER TOURNAMENTS",
   "SLOTS TOURNAMENTS",
   "ROULLETTE/CRAPS TOURNAMENTS",
   "BLACKJACK TOURNAMENTS",
   "BINGO/CHARITY BINGO"
 };


  // strings for child elements

 static final String arrChildelements[][] = 
 {
   {
  "TEXAS HOLD'EM",
  "OMAHA HIGH-LOW",
  "SEVEN CARD STUD",
  "THREE CARD POKER",
  "OTHER POKER VARIANTS",
  "ONLINE/SATTELITE TOURNAMENTS"
   },
   {
  "SLOTS"
   },
   {
  "ROULLETTE",
  "CRAPS"

   },
   {
  "BLACKJACK"
   },
   {
       "BINGO"
        }
    };    

按照以下方式使用onChildClick函数将字符串的值设置为“TEXAS HOLD'EM”,当点击下面的孩子时

@Override
        public boolean onChildClick(ExpandableListView parent, View v,
                int groupPosition, int childPosition, long id) {
            //ExpandableListAdapter adapter = getExpandableListAdapter();
            gametype = ExpList.arrChildelements[groupPosition][childPosition];
            //---------------------
            Intent pullt = new Intent(ExpList.this,
                    SearchActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("gametype", gametype);
            pullt.putExtras(bundle);
            pullt.putExtra("gametype", gametype);

            startActivity(pullt);
            //---------------------
            return false;
        }

2 个答案:

答案 0 :(得分:0)

onChildClick()中,您获得groupPositionchildPosition

ExpandableListAdapter adapter = getExpandableListAdapter();
gametype = adapter.getChild(groupPosition, childPosition).toString;

答案 1 :(得分:0)

public class ExpList extends ExpandableListActivity
{
 String gametype;

  // strings for group elements

    static final String arrGroupelements[] = 
    {
   "POKER TOURNAMENTS",
   "SLOTS TOURNAMENTS",
   "ROULLETTE/CRAPS TOURNAMENTS",
   "BLACKJACK TOURNAMENTS",
   "BINGO/CHARITY BINGO"
 };


  // strings for child elements

 static final String arrChildelements[][] = 
 {
   {
  "TEXAS HOLD'EM",
  "OMAHA HIGH-LOW",
  "SEVEN CARD STUD",
  "THREE CARD POKER",
  "OTHER POKER VARIANTS",
  "ONLINE/SATTELITE TOURNAMENTS"
   },
   {
  "SLOTS"
   },
   {
  "ROULLETTE",
  "CRAPS"

   },
   {
  "BLACKJACK"
   },
   {
       "BINGO"
        }
    };    

按照以下方式使用onChildClick函数将字符串的值设置为“TEXAS HOLD'EM”,当点击下面的孩子时

@Override
        public boolean onChildClick(ExpandableListView parent, View v,
                int groupPosition, int childPosition, long id) {
            //ExpandableListAdapter adapter = getExpandableListAdapter();
            gametype = ExpList.arrChildelements[groupPosition][childPosition];
            //---------------------
            Intent pullt = new Intent(ExpList.this,
                    SearchActivity.class);
            Bundle bundle = new Bundle();
            bundle.putString("gametype", gametype);
            pullt.putExtras(bundle);
            pullt.putExtra("gametype", gametype);

            startActivity(pullt);
            //---------------------
            return false;
        }