Hide Android Counter Text

I have a counter with a background image. But when I add an array adapter to the counter, the text is displayed on the background image. I want to hide this text. There is also a TextView. My requirement is that when I click on the image, a counter should appear, and when I select an item, the TextView is updated with the selected item.

+3
source share
3 answers
Spinner spin = (Spinner) d.findViewById(R.id.searchCriteria);  
spin.setOnItemSelectedListener(new OnItemSelectedListener() {  
  public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {  
// hide selection text  
((TextView)view).setText(null);  
// if you want you can change background here  
}  
  public void onNothingSelected(AdapterView<?> arg0) {}  
 });
+9
source

Create ghost_text.xml in the layouts folder using this text:

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:textColor="@android:color/transparent" />

Then use this file in your adapter as follows:

    ArrayAdapter<String> your_adapter = new ArrayAdapter<String>(this, 
        R.layout.ghost_text, your_list);
    your_spinner.setAdapter(your_adapter);

You should also use this technique with other resource based adapters.

+1
source

, xml-layout, , .

. empty_spinner_item.xml

<ImageView xmlns:android="http..."
    android:layout_width=".." 
/>

:

spinner.setAdapter(new SimpleAdapter(this, data, R.layout.empty_spinner_item, ... ));
0

Source: https://habr.com/ru/post/1790650/


All Articles