0

I prepared html codes in string.xml. I want to show html text in textview at secondactivity after button click. But I couldnt. I mean every html tags still there.

here my codes in main activity.

 bir.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String veri = getString(R.string.dahi);
            Intent intent = new Intent(MainActivity.this, Main2Activity.class);
            intent.putExtra("veri", veri);
            startActivity(intent);

        }
    });

}

//and here is second activity:

te=(TextView)findViewById(R.id.te);
    Intent intent=getIntent();
    String gelenVeri=``intent.getStringExtra("veri");
    te.setText(gelenVeri);
enter code here

I want to see normal text after buttonclick, yet I still html codes. what can I do? thanks everyone.

syam
  • 799
  • 1
  • 12
  • 30
a.dem
  • 11
  • 1
  • 7

3 Answers3

0

try this

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
   te.setText(Html.fromHtml(gelenVeri, Html.FROM_HTML_MODE_LEGACY));
} else {
   te.setText(Html.fromHtml(gelenVeri));
}
0

I think you should define two string values in your strings.xml file. One with html tags and another without html tags. let name them tagged_str and simple_str.

first, you show your html string in textview like below:

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

 te.setText(Html.fromHtml(getString(R.string.tagged_str), Html.FROM_HTML_MODE_COMPACT));
    } else {
        te.setText(Html.fromHtml(R.string.tagged_str));
    }

then in your on click listener, load simple string:

        button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
           te.setText(R.string.simple_str); 
        }
    });
salmanseifian
  • 1,082
  • 3
  • 9
  • 26
0

Thanks for your fast reply but I couldnt. infact ı want simple way. so ı have about 20 button and 20 article with word doc. I dont want to create 20 layout for each article. ı want click a button and it will go their own html doc. ı dont want to add pdf file.

a.dem
  • 11
  • 1
  • 7