So I am not entirely sure why this is occurring:
Below I'm using the default android.R.layout.simple_list_item_1
layout and the code works like a charm, where the OnItemClickListener
working as desired.
playerAliasAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, usernameList);
playersAliasSelected.setAdapter(playerAliasAdapter);
playersAliasSelected.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedItemText = (String) parent.getItemAtPosition(position);
Toast.makeText(getBaseContext(),selectedItemText + " selected!", Toast.LENGTH_LONG).show();
}
});
Now below is the exact same code with the exception this is my own custom layout R.layout.number_of_players_dropdown_layout
In this instance, the OnItemClickListener
is NOT triggering and not working!?
numPlayersSelected = (AutoCompleteTextView) findViewById(R.id.numOfPlayersAddSelected);
numPlayersAdapter = new IAPSkuAdapter(activity, R.layout.number_of_players_dropdown_layout, numPlayersArray);
numPlayersSelected.setAdapter(numPlayersAdapter);
// NOT WORKING!? <-------------------------------------
numPlayersSelected.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedItemText = (String) parent.getItemAtPosition(position);
Toast.makeText(getBaseContext(),selectedItemText + " selected!", Toast.LENGTH_LONG).show();
Log.e(TAG, "<< SELECTED >> : " + selectedItemText);
}
}
R.layout.number_of_players_dropdown_layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- Name of SKU -->
<TextView
android:id="@+id/skuTitle"
android:layout_height="wrap_content"
android:layout_width="250dp"
android:padding="14dp"
android:maxLines="1"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textColor="#000"
android:textSize="16sp"
android:background="#fff"
android:text="Name" />
<!-- Price of SKU -->
<TextView
android:id="@+id/skuPrice"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="14dp"
android:maxLines="1"
android:ellipsize="end"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textColor="#000"
android:textSize="16sp"
android:background="#fff"
android:gravity="right"
android:text="Price" />
</LinearLayout>
Can some help me figure how to resolve this!?