Search code examples
androidspinnerstrikethrough

How to strike specific text in Spinner android?


I want to strike specific text in Spinner, My code look like below code

    packSpinner = findViewById(R.id.packSpinner);
    String spinnerArray[] = new String[10];

    for(int i=0; i<8; i++){
      spinnerArray[i] = packArray[i] + mrpArray[i] + sellingPriceArray[i];
    }

    packSpinner.setAdapter(new ArrayAdapter<String>(getActivity(),                 
    android.R.layout.simple_list_item_1, spinnerArray));

In above code products coming from server and i already extracted that data into packArray, mrpArray and sellingPriceArray, now i want to mrp text should be striked.


Solution

  • you can use StrikethroughSpan or just set textView.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); but for both you must have access to TextView, so you can't achieve your purposes with defaut ArrayAdapter, it was designed to show simple lists without custom effects (most common usage). you have to extend it and override getView method. some examples HERE, HERE and HERE