logo
down
shadow

How to assign multiple string resources to a single textview?


How to assign multiple string resources to a single textview?

Content Index :

How to assign multiple string resources to a single textview?
Tag : android , By : user181345
Date : November 29 2020, 12:01 PM

wish of those help I have created 3 strings in string resources. Every string has an external link in it. Basically I am trying to put one sentence in a TextView which has 3 outside links in it. Please tell how to do this in Android. , You have to use Spannable, here is example below, have a look
ClickableSpan linkClick = new ClickableSpan() {
@Override
public void onClick(View view) {
    Toast.makeText(getApplicationContext(), "Link Click",
            Toast.LENGTH_SHORT).show();
    view.invalidate();
}

@Override
public void updateDrawState(TextPaint ds) {
    if (textView.isPressed()) {
        ds.setColor(Color.BLUE);
    } else {
        ds.setColor(Color.RED);
    }
    textView.invalidate();
  }
};
textView.setHighlightColor(Color.TRANSPARENT);

Spannable spannableString = new SpannableString("Link in TextView");
spannableString.setSpan(linkClick, 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spannableString, TextView.BufferType.SPANNABLE);
textView.setMovementMethod(LinkMovementMethod.getInstance());

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Display string as a multiple tag in a single TextView


Tag : java , By : rajiv
Date : March 29 2020, 07:55 AM
should help you out The first thing, I know how to split the string and my question is not about splitting it at comma or space. , create your chip layout like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/background_chip"
    android:gravity="center"
    android:paddingLeft="4dp"
    android:paddingRight="4dp">
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/background_chip"
    android:gravity="center"
    android:paddingBottom="6dp"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="6dp">

    <TextView
        android:id="@+id/chip_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="6dp"
        android:text="#SoftwereEngineer"
        android:textColor="@android:color/white"
        android:textSize="14sp" />

</LinearLayout>
</LinearLayout>
 <LinearLayout
    android:id="@+id/chip_container
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/background_chip"
    android:gravity="center"
    android:orientation:"horizontal"
    android:paddingBottom="4dp"
    android:paddingTop="4dp"/>
LinearLayout linearLayout = view.findViewById(R.id.chip_container);
for(int i = 0; i < list.size ; i++){
final View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_chip, null);
    ((TextView) view.findViewById(R.id.chip_text)).setText(list.get(i));
    linearLayout.addView(view);
}
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

     <solid android:color="#cac8c8"/>
     <corners android:radius="20dp"/>
</shape>

How to assign multiple values to a single string in Java with an array?


Tag : java , By : moss
Date : March 29 2020, 07:55 AM
Hope that helps The most proper to do this is to have an object representing the combination of values you have;
public class Enemy {

    private String name;
    private Integer healthPoint;
    private Integer manaPoint;
    private Integer attackPower;

    // getter, setter, constructors
    // example constructor
    public Enemy(String name, Integer hp, Integer mp, Integer ap) {
        this.name = name;
        this.healthPoint = hp;
        this.manaPoint = mp;
        this.attackPower = ap;
    }
}
List<Enemy> enemies = new ArrayList<>();
enemies.add(new Enemy("Weak Skeleton", 100, 0, 100));
enemies.add(new Enemy("Blue Slime", 50, 0, 25));
enemies.add(new Enemy("Novice Rogue Mage", 25, 100, 0));
Map<String, Enemy> enemyMap = enemies.stream().collect(Collectors.groupingBy(Enemy::getName));
enemyMap.get("Weak Skeleton").setAttackPower(75);
Enemy dragonBoss = new Enemy("Dragon Boss", 1000, 500, 250);
enemyMap.put(dragonBoss.getName(), dragonBoss);
public enum EnemyType { 

    WEAK_SKELETON("Weak Skeleton"), BLUE_SLIME("Blue Slime"), NVC_ROGUE_MAGE("Novice Rogue Mage"); 

    private String name; 

    public String getName() { 
        return this.name; 
    }

    private EnemyType (String name) {
        this.name = name;
    } 
} 

Assign multiple string to a single variable


Tag : development , By : goffi
Date : March 29 2020, 07:55 AM
will be helpful for those in need Problem is that you need to encode slashes and comma as ascii character, as without it they are implemented as part of variable (for example string opening). So code in your button should be:
=chr(39) & 'Go Web' & chr(39) & chr(44) & chr(39) & 'Go Call' & chr(39)
=Sum( {$< COMPANYNAME={$(vCompany)} >} Staff)

How to assign a single char to a TextView


Tag : java , By : Jesenko Mehmedbasic
Date : March 29 2020, 07:55 AM

Can a single textView display two different texts from two different string resources?


Tag : java , By : mdiezb
Date : March 29 2020, 07:55 AM
Any of those help I want to use the same layout with TextViews but change the text in the TextViews alternately when someone clicks a RadioButton on/off. While the RadioButton were programmatically in mainactivity and transferred the boolean value through an intent; using the boolean value, I'm planning to use an if/else statement for the on/off text changes programmatically in activity. I put the texts in resources `string.xml . , Yes you can do that. Refer the following code
radioButton.setOnCheckedChangeListener(newCompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
   if(isChecked)

      textview.setText(getString(R.string.string1));
   else

      textview.setText(getString(R.string.string2));

   }
}); 
Related Posts Related QUESTIONS :
  • Jetifier not working when library uses android component and app uses androidx component
  • How can I write the contents of an image in a filesystem
  • Retrieve a list of images from the Database and display them using a ListView?
  • java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION
  • Timer/hourglass wont stop
  • How can I make AndroidX the default library for new Android projects?
  • Is it okay to delete buildToolsVersion android studio because of a warning in the Asyncstorage library?
  • Can I call a class that doesn't have an activity withIntent?
  • Android TextView fontFamily not working when set via TextAppearance
  • Unable to find nearby places
  • Is there any way to launch my application right away without 'Ok Google"?
  • Places api set location biased based on current location
  • Layout Preview is not displaying layout when Material Design is added
  • How do I resolve this diamond problem in Kotlin?
  • How to update the custom value in a view model object
  • How to stop refreshing/re-creating activity when updating Firebase data using setValue?
  • Manifest Permissions vs App Setttings Permissions
  • NumberFormatException in Try-Catch while converting String to Int
  • How to pass observable fields through include tag?
  • Next button on Android keyboard not submitting form
  • Does Firestore support automatic functions for updates?
  • Why app crashing because of a missing dimension (for google maps) only when I apply changes?
  • How to make a grouping, ordering and sorting: Kotlin collection
  • how to use augmented reality to change the color of a qr code once it is detected using with arcore and ml kit firebase
  • how to resolve Firebase projects adding quota problem?
  • Why it Kotlin giving me the wrong Int value when converting from a String
  • How to add bottom navigation listeners to fragments
  • Why is scrollview hiding buttons behind other views?
  • Open Settings using Linking.sendIntent()
  • How do I access an unknown node in firebase while retrieving data?
  • Can't retrieve list of all users from firebase authetication
  • many activities with same content (adview, reward adview, functions...) how to avoid repeating code?
  • Popup doesn't hide when touch outside
  • proper way to handling images in Android? by using Firebase
  • Android: Button is faded gray when it should be transparent
  • Gradle DSL method not found: 'deleteAllActions()'
  • In Clean Architecture, must Repository is Android or Kotlin module?
  • Kotlin parse double from string
  • Inconsistency detected. Invalid view holder adapter positionViewHolder
  • In App Update API always returns 1 (UPDATE_NOT_AVAILABLE)
  • Event of ImageView when click
  • Basic precautions to prevent piracy?
  • What is the difference between 'center' and 'centerCrop' in the "ImageView"?
  • Unable to receive SIP calls when app is killed
  • Android emulator not processing http get request, but iOS simulator works fine
  • Android Problem with sharing temporary file
  • How to add Broadcast in Android?
  • How to hide 'Running in Chrome' toast on TWA application on Android devices?
  • How to Fix Error: Could not find method deleteAllActions() for arguments [] on task
  • Android Deep Linking not working with https
  • WARNING: API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'
  • setSupportActionBar (androidx.appcompat.widget.Toolbar) in AppCompatActivity¬†cannot be applied
  • Manifest merger failed after adding Firebase core version 17.0.0
  • Marker from Firestore map data type
  • Cordova signed apk produces a blank screen after splash screen
  • How to clear EditText input from all item views of RecyclerView?
  • Android Studio Mac Fresh install - error after error after error
  • Android Q, programmatically connect to different WiFi AP for internet
  • Application is becoming very slow while retrieving data from server
  • How to get Accelerometer value in Android XAML App(Xamarin.Forms)
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com