0

I have a grid view in which I need to display radio buttons that allows the user to change the displayed language. When I click on the grid item it has to uncheck the other radio buttons and also change the display text to black for the selected option and to grey for the other ones. I am able to display the options in the grid but the problem is when I'm clicking on the item is not responding (setOnItemClickListener is not firing up). I couldn't figure out where have I done wrong.

This is how the layout that is inflated for each cell looks like:

<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textLanguageName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left|center_vertical"
android:paddingLeft="10sp"
android:textColor="#000"
android:text="radioButton"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"/>

And the grid:

<GridView
            android:id="@+id/gridview_setup_language"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:numColumns="2"
            android:verticalSpacing="5dp"
            android:horizontalSpacing="5dp"
            android:listSelector="#00000000"
            android:paddingTop="20sp"
            android:layout_below="@+id/textSettingsLanguage" />

And the clicked item:

m_oLanguagesGridview = (GridView) findViewById(R.id.gridview_setup_language);
    m_oImageAdapterGridViewLanguages = new GridViewLanguagesAdapter(this,m_sSelectedLanguage);
    m_oLanguagesGridview.setAdapter(m_oImageAdapterGridViewLanguages);
    m_oLanguagesGridview.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
        public void onItemClick(AdapterView<?> parent, android.view.View v, int position, long id)
        {
            LanguagePanel languagePanel = (LanguagePanel)m_oImageAdapterGridViewLanguages.getItem(position);
            m_sSelectedLanguage = languagePanel.m_sLanguage;
            displaySelectedLanguage(m_sSelectedLanguage);
            refreshTranslationsOnSettingPage();
        }
    });

Is there at least a way to get the position of the clicked item from the GridView?

I'm new in Android programming so please be gentle :)

LAffair
  • 1,968
  • 5
  • 31
  • 60
  • Are you using a `RadioGroup` for your `RadioButton`s, and have you tried using a `onCheckedChangedListener` instead of a `onItemClickedListener`? [Check out this question about it.](https://stackoverflow.com/questions/18536195/android-oncheckedchanged-for-radiogroup) – evanklicker Aug 11 '17 at 14:32
  • The thing is that I only need to get the position of the clicked radio button from the grid and I don't think I can do that using RadioGroup – LAffair Aug 11 '17 at 16:34
  • I've tried adding onClick method on the radio button, but I need to get it's position in the grid and I don't know how :( – LAffair Aug 11 '17 at 16:36
  • Do the `RadioButton`s HAVE to be in the `GridView`? Or can you put them in something else and arrange them as if they were in a `GridView`? – evanklicker Aug 11 '17 at 18:16
  • No, they don't have to be in the GridView. – LAffair Aug 14 '17 at 13:58

0 Answers0