1. Are you ready for the Galaxy S20? Here is everything we know so far!

Apps Help!!!!

Discussion in 'Android Development' started by aattaa, Feb 13, 2011.

  1. aattaa

    aattaa Lurker
    Thread Starter

    Hi,
    I need help!!! my code is near the page. And my question is:

    I want to show the word image by clicking on the word. How can I create onclicklistener in the ExpandableList?

    Thanks

    public class Categories extends ExpandableListActivity {

    private static final String NAME = "NAME";


    private ExpandableListAdapter mAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    DBManager db = new DBManager(getApplicationContext());

    List<String> header = db.selectAllCategories();
    List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
    List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();

    for (String category : header) {
    Map<String, String> curGroupMap = new HashMap<String, String>();
    groupData.add(curGroupMap);
    curGroupMap.put(NAME, category);


    List<String> categoryWords = db.selectWordsFromCategory(category);

    List<Map<String, String>> children = new ArrayList<Map<String, String>>();
    for (String word : categoryWords) {
    Map<String, String> curChildMap = new HashMap<String, String>();
    children.add(curChildMap);

    curChildMap.put(NAME, word);

    }
    childData.add(children);
    }


    mAdapter = new SimpleExpandableListAdapter(
    this,
    groupData,
    android.R.layout.simple_expandable_list_item_1,
    new String[] { NAME },
    new int[] { android.R.id.text1 },
    childData,
    android.R.layout.simple_expandable_list_item_2,
    new String[] { NAME },
    new int[] { android.R.id.text1 }
    );

    setListAdapter(mAdapter);
    }


    }
     

    Advertisement

  2. pietjuhhh1990

    pietjuhhh1990 Well-Known Member

    set both in your script

    public class Categories extends ExpandableListActivity implements OnClickListener {

    //code
    View myButton = findViewById(R.id.myButton );
    myButton .setOnClickListener(this);

    View myButton2 = findViewById(R.id.myButton2 );
    myButton2 .setOnClickListener(this);

    }

    public void onClick(View v) {
    switch (v.getId()){
    case R.id.myButton:
    //myButton clicked
    }
    break;
    case R.id.myButton2:
    //myButton2 clicked
    break;
    }
    };



    this should be enough ;)
     
Loading...
Similar Threads - Help
  1. Colton Mcclure
    Replies:
    4
    Views:
    118
  2. Bingo2003
    Replies:
    8
    Views:
    269
  3. jthompff
    Replies:
    2
    Views:
    150
  4. addermc
    Replies:
    3
    Views:
    144
  5. MoodyBlues
    Replies:
    0
    Views:
    115
  6. CindysPhonesare4calls
    Replies:
    4
    Views:
    261
  7. Donna ALTHOUSE
    Replies:
    3
    Views:
    188
  8. Android News
    Replies:
    0
    Views:
    47
  9. Android News
    Replies:
    0
    Views:
    12

Share This Page

Loading...