Найти тему

Создание приложение для Android c WebView, меню и 8 кнопками. Часть 4

Рис. Приложение для Android c WebView, меню и 8 кнопками (два экрана). Горизонтальной стрелкой (на сером поле) отражён процесс "листания" страниц. Вертикальной стрелкой показан "перенос" названий 10 кнопок с соответствующими ссылками из нижнего текстового поля (куда можно вставить текст из буфера обмена).
Рис. Приложение для Android c WebView, меню и 8 кнопками (два экрана). Горизонтальной стрелкой (на сером поле) отражён процесс "листания" страниц. Вертикальной стрелкой показан "перенос" названий 10 кнопок с соответствующими ссылками из нижнего текстового поля (куда можно вставить текст из буфера обмена).

Здесь рассказывается, как усовершенствовать приложение, чтобы оно загружало 10 пользовательских ссылок и позволяло открывать их через "нижние кнопки", а также "перелистыванием" (см. Рис). Предполагается изменение текста в следующих файлах: MainActivity.java, activity_main.xml, inputActivity.java, main_menu.xml, strings.xml

Если вы не читали предыдущие части, то вначале выполните то, что написано в первых двух частях:

Создание приложение для Android c WebView, меню и 8 кнопками. Часть 1
Датамайнинг, дайджесты, диалоги, дискуссии5 августа 2022
Создание приложение для Android c WebView, меню и 8 кнопками. Часть 2
Датамайнинг, дайджесты, диалоги, дискуссии12 августа 2022

Третью часть читать не обязательно, потому что все упомянутые там файлы будут полностью переписаны в этой части.

1. В файле MainActivity.java удалите все строки и вставьте:

package com.digestviewer;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.annotation.TargetApi;

import android.widget.LinearLayout;
import android.widget.Button;
import android.view.View;


public class MainActivity extends AppCompatActivity {

WebView webView;

int curLink=1;

//
SwipeListener swipeListener;
RelativeLayout relativeLayout;


TextView textView;



@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

final Activity activity = this;
SharedPreferences sharedPref0 = activity.getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor0 = sharedPref0.edit();

// Handle item selection

switch (item.getItemId()) {
case R.id.menu_sc10:
webView.setInitialScale(10);
editor0.putInt(getString(R.string.saved_scale), 10);
editor0.apply();
return true;
case R.id.menu_sc25:
webView.setInitialScale(25);
editor0.putInt(getString(R.string.saved_scale), 25);
editor0.apply();
return true;
case R.id.menu_sc50:
webView.setInitialScale(50);
editor0.putInt(getString(R.string.saved_scale), 50);
editor0.apply();
return true;
case R.id.menu_sc100:
webView.setInitialScale(100);
editor0.apply();
return true;
case R.id.menu_sc150:
webView.setInitialScale(150);
editor0.putInt(getString(R.string.saved_scale), 150);
editor0.apply();
return true;
case R.id.menu_sc200:
webView.setInitialScale(200);
editor0.putInt(getString(R.string.saved_scale), 200);
editor0.apply();
return true;
case R.id.menu_sc300:
webView.setInitialScale(300);
editor0.putInt(getString(R.string.saved_scale), 300);
editor0.apply();
return true;
case R.id.menu_clear:
//webView.setInitialScale(300);
//editor0.putInt(getString(R.string.saved_scale), 300);
//editor0.apply();
//return true;
SharedPreferences sharedPref = getSharedPreferences("Selection", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
//String message1 = txtA1.getText()+";"+txtA2.getText()+";"+txtB1.getText()+";"+txtB2.getText()+";"+txtC1.getText()+";"+txtC2.getText()+";"+txtD1.getText()+";"+txtD2.getText()+";"+txtE1.getText()+";"+txtE2.getText()+";"+txtF1.getText()+";"+txtF2.getText()+";"+txtG1.getText()+";"+txtG2.getText()+";"+txtH1.getText()+";"+txtH2.getText()+";"+txtI1.getText()+";"+txtI2.getText()+";"+txtJ1.getText()+";"+txtJ2.getText();
editor.putString(getString(R.string.saved_links), "");
editor.apply();

default:
return super.onOptionsItemSelected(item);
}

}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
//relativeLayout = findViewById(R.id.relative_layout);
//textView = findViewById(R.id.textView);
textView = new TextView(this); //findViewById(R.id.textView);
webView = new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
final Activity activity = this;
webView.setWebViewClient(new WebViewClient() {
@SuppressWarnings("deprecation")
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}

@TargetApi(android.os.Build.VERSION_CODES.M)
@Override
public void onReceivedError(WebView view, WebResourceRequest req, WebResourceError rerr) {
// Redirect to deprecated method, so you can use it in all SDK versions
onReceivedError(view, rerr.getErrorCode(), rerr.getDescription().toString(), req.getUrl().toString());
}
});

webView.loadUrl("http://www.tablepedia.com/");
webView.setInitialScale(200);
SharedPreferences sharedPref = getSharedPreferences("Selection", MODE_PRIVATE);
String actualJoin = sharedPref.getString(getString(R.string.saved_links), "");
//String actualJoin = sharedPref.getString(getString(R.string.saved_links) + ";;;;;;;;;;", "Info1;http://nanopedia.site/;Info2;http://ipedia.site/;Info3;http://telepedia.site/;Info4;http://www.quatrecoin.com/");
final String[] splitted = actualJoin.split(";");

LinearLayout buttonsView = new LinearLayout(this);
buttonsView.setOrientation(LinearLayout.VERTICAL);

LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); // Verbose!
lp2.setMargins(0, 0, 0, 0);
lp2.weight = 0.1f; // This is critical. Doesn't work without it.

LinearLayout.LayoutParams lpW = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); // Verbose!
lpW.setMargins(10, 10, 10, 10);
lpW.weight = 1.0f; // This is critical. Doesn't work without it.

//LinearLayout linear = (LinearLayout) activity.findViewById(R.id.itemList);

LinearLayout row = new LinearLayout(this);
row.setOrientation(LinearLayout.HORIZONTAL);
row.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

Button btnBack = new Button(this);
btnBack.setText("<---");
btnBack.setTextSize(12);
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
webView.goBack();
}
});
row.addView(btnBack, lp2);


Button btnT = new Button(this);
btnT.setText("Tablepedia");
btnT.setTextSize(12);
btnT.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
webView.loadUrl("http://www.tablepedia.com/");
}
});
row.addView(btnT, lp2);

Button btnS = new Button(this);
btnS.setText("Settings");
btnS.setTextSize(12);
btnS.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openActivity2();
}
});
row.addView(btnS, lp2);

Button btnForward = new Button(this);
btnForward.setText("--->");
btnForward.setTextSize(12);
btnForward.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
webView.goForward();
}
});
row.addView(btnForward, lp2);

LinearLayout row2 = new LinearLayout(this);
row2.setOrientation(LinearLayout.HORIZONTAL);
row2.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

Button btnInfo1 = new Button(this);
if (splitted.length>1) {
btnInfo1.setText(splitted[0]);
} else {
btnInfo1.setText("Info1");
}
btnInfo1.setTextSize(12);
btnInfo1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (splitted.length>1) webView.loadUrl(splitted[1]); else webView.loadUrl("http://ipedia.site/");
curLink=1;
}
});
row2.addView(btnInfo1, lp2);

Button btnInfo2 = new Button(this);
if (splitted.length>2) {
btnInfo2.setText(splitted[2]);
} else {
btnInfo2.setText("Info2");
}
btnInfo2.setTextSize(12);
btnInfo2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (splitted.length>3) webView.loadUrl(splitted[3]); else webView.loadUrl("http://telepedia.site/");
curLink=3;
}
});
row2.addView(btnInfo2, lp2);

Button btnInfo3 = new Button(this);
if (splitted.length>4) {
btnInfo3.setText(splitted[4]);
} else {
btnInfo3.setText("Info3");
}
btnInfo3.setTextSize(12);
btnInfo3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (splitted.length>5) webView.loadUrl(splitted[5]); else webView.loadUrl("http://www.quatrecoin.com/");
curLink=5;
}
});
row2.addView(btnInfo3, lp2);

Button btnInfo4 = new Button(this);
if (splitted.length>6) {
btnInfo4.setText(splitted[6]);
} else {
btnInfo4.setText("Info4");
}
btnInfo4.setTextSize(12);
btnInfo4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (splitted.length>7) webView.loadUrl(splitted[7]); else webView.loadUrl("http://nanopedia.site/");
curLink=7;
}
});

row2.addView(btnInfo4, lp2);


final TextView tw2 = new TextView(this);
tw2.setHeight(100);

textView.setHeight(200);

buttonsView.addView(row, lp2);
buttonsView.addView(textView, lp2);
buttonsView.addView(webView, lpW);
buttonsView.addView(row2, lp2);
//
setContentView(buttonsView, lpW);

//relativeLayout = findViewById(R.id.relative_layout);
relativeLayout = findViewById(R.id.relative_layout);

//relativeLayout.setOnTouchListener(new SwipeListener(buttonsView));
//setContentView(relativeLayout, lpW);
//
//////////////////swipeListener=new SwipeListener(relativeLayout);
//
//buttonsView.setOnTouchListener(new SwipeListener(webView));
//////////buttonsView.setOnTouchListener(new SwipeListener(buttonsView));
//
buttonsView.setOnTouchListener(new SwipeListener(tw2));

}

public void openActivity2() {
Intent intent = new Intent(this, inputActivity.class);
startActivity(intent);
}


private class SwipeListener implements View.OnTouchListener {
GestureDetector gestureDetector;

SharedPreferences sharedPref = getSharedPreferences("Selection", MODE_PRIVATE);
String actualJoin = sharedPref.getString(getString(R.string.saved_links), "");
//String actualJoin = sharedPref.getString(getString(R.string.saved_links) + ";;;;;;;;;;", "Info1;http://nanopedia.site/;Info2;http://ipedia.site/;Info3;http://telepedia.site/;Info4;http://www.quatrecoin.com/");
final String[] splitted = actualJoin.split(";");

SwipeListener(View view) {
final int threshold = 50;
final int velocity_threshold = 50;
GestureDetector.SimpleOnGestureListener listener =
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
return true; //super.onDoubleTap(e);
}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//
float xDiff = e2.getX() - e1.getX();
float yDiff = e2.getY() - e1.getY();
try {

//openActivity2();

if (Math.abs(xDiff) > Math.abs(yDiff)) {
if (Math.abs(xDiff) > threshold
&& Math.abs(velocityX) > velocity_threshold) {
if (xDiff > 0) {
curLink=curLink-2;
if (curLink<0) curLink=curLink+20;
if (curLink>0) webView.loadUrl(splitted[curLink]);
//tw2.setText("Swiped Right");
//tw2.
//openActivity2();
} else {
//textView.setText("Swiped Left");
curLink=curLink+2;
if (curLink>20) curLink=curLink-20;
if (curLink>0) webView.loadUrl(splitted[curLink]);
//openActivity2();
}
return true;
}
} else {
if (Math.abs(yDiff) > threshold
&& Math.abs(velocityY) > velocity_threshold) {
if (yDiff < 0) {
textView.setText("Swiped Up");
} else {
textView.setText("Swiped Down");
}
return true;
}
}

} catch (Exception e) {
e.printStackTrace();
}
return false;
}

};
gestureDetector =new GestureDetector(listener);
view.setOnTouchListener(this);


}


@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return gestureDetector.onTouchEvent(motionEvent); //false; //super.onDoubleTap(e);
}
}


}

2. В файле activity_main.xml удалите все строки и вставьте:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relative_layout"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:text="Swipe Gesture"
android:textSize="100sp"
android:textStyle="bold"
android:layout_centerInParent="true"
/>

<WebView>
android:id="@+id/webview_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
</WebView>

</RelativeLayout>

3. В файле inputActivity.java удалите все строки и вставьте:

package com.digestviewer;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;


public class inputActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_input);
LinearLayout buttonsView = new LinearLayout(this);
buttonsView.setOrientation(LinearLayout.VERTICAL);

LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); // Verbose!
lp2.setMargins(0, 0, 0, 0);
lp2.weight = 0.1f; // This is critical. Doesn't work without it.

LinearLayout.LayoutParams lpW = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); // Verbose!
lpW.setMargins(10, 10, 10, 10);
lpW.weight = 0.1f; // This is critical. Doesn't work without it.

LinearLayout row = new LinearLayout(this);
row.setOrientation(LinearLayout.HORIZONTAL);
row.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

LinearLayout row2 = new LinearLayout(this);
row2.setOrientation(LinearLayout.HORIZONTAL);
row2.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

LinearLayout row3 = new LinearLayout(this);
row3.setOrientation(LinearLayout.HORIZONTAL);
row3.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

LinearLayout row4 = new LinearLayout(this);
row4.setOrientation(LinearLayout.HORIZONTAL);
row4.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

LinearLayout row5 = new LinearLayout(this);
row5.setOrientation(LinearLayout.HORIZONTAL);
row5.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

LinearLayout row6 = new LinearLayout(this);
row6.setOrientation(LinearLayout.HORIZONTAL);
row6.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

LinearLayout row7 = new LinearLayout(this);
row7.setOrientation(LinearLayout.HORIZONTAL);
row7.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

Button btnExit = new Button(this);
btnExit.setText("Exit");
btnExit.setTextSize(12);
btnExit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openActivity1();
}
});
row.addView(btnExit, lp2);

final EditText txtA1 = new EditText(this);
row3.addView(txtA1, lp2);
final EditText txtA2 = new EditText(this);
row3.addView(txtA2, lp2);
final EditText txtB1 = new EditText(this);
row4.addView(txtB1, lp2);
final EditText txtB2 = new EditText(this);
row4.addView(txtB2, lp2);
final EditText txtC1 = new EditText(this);
row5.addView(txtC1, lp2);
final EditText txtC2 = new EditText(this);
row5.addView(txtC2, lp2);
final EditText txtD1 = new EditText(this);
row6.addView(txtD1, lp2);
final EditText txtD2 = new EditText(this);
row6.addView(txtD2, lp2);

final EditText txtE1 = new EditText(this);
//row8.addView(txtE1, lp2);
final EditText txtE2 = new EditText(this);
//row8.addView(txtE2, lp2);

final EditText txtF1 = new EditText(this);
//row10.addView(txtF1, lp2);
final EditText txtF2 = new EditText(this);
//row11.addView(txtF2, lp2);

final EditText txtG1 = new EditText(this);
final EditText txtG2 = new EditText(this);
final EditText txtH1 = new EditText(this);
final EditText txtH2 = new EditText(this);


final EditText txtI1 = new EditText(this);
final EditText txtI2 = new EditText(this);
final EditText txtJ1 = new EditText(this);
final EditText txtJ2 = new EditText(this);

final EditText txtMulti = new EditText(this);
txtMulti.setMaxLines(10);
row7.addView(txtMulti, lp2);

SharedPreferences sharedPref;
sharedPref = getSharedPreferences("Selection", MODE_PRIVATE);
String mTest=sharedPref.getString(getString(R.string.saved_links), "");
//String actualJoin = sharedPref.getString(getString(R.string.saved_links)+";;;;;;;;;;", "Info1;http://nanopedia.site/;Info2;http://ipedia.site/;Info3;http://telepedia.site/;Info4;http://www.quatrecoin.com/");
String actualJoin = sharedPref.getString(getString(R.string.saved_links), "");
String[] splitted = actualJoin.split(";");
char someChar = ';';
int count = 0;

//if (actualJoin.length()>5) {
// for (int i = 0; i < actualJoin.length(); i++) {
// if (actualJoin.charAt(i) == someChar) {
//if (count == 0)
if (splitted.length>0) txtA1.setText(splitted[0]);
//if (count == 1)
if (splitted.length>1) txtA2.setText(splitted[1]);
//if (count == 2)
if (splitted.length>2) txtB1.setText(splitted[2]);
//if (count == 3)
if (splitted.length>3) txtB2.setText(splitted[3]);
//if (count == 4)
if (splitted.length>4) txtC1.setText(splitted[4]);
//if (count == 5)
if (splitted.length>5) txtC2.setText(splitted[5]);
//if (count == 6)
if (splitted.length>6) txtD1.setText(splitted[6]);
//if (count == 7)
if (splitted.length>7) txtD2.setText(splitted[7]);

//txtE1.setText(splitted[8]);
//txtE2.setText(splitted[9]);

// txtF1.setText(splitted[10]);
//txtF2.setText(splitted[11]);

//txtG1.setText(splitted[12]);
//txtG2.setText(splitted[13]);
//txtH1.setText(splitted[14]);
//txtH2.setText(splitted[15]);

//txtI1.setText(splitted[16]);
//txtI2.setText(splitted[17]);
//txtJ1.setText(splitted[18]);
//txtJ2.setText(splitted[19]);

// count++;
// }
// }
//}

final Button btnDefault = new Button(this);
btnDefault.setText("User Links");
btnDefault.setTextSize(12);
btnDefault.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String message = txtMulti.getText().toString().replaceAll("\\n", ";")+";";
message = message.replaceAll(";;;;;", ";");
message = message.replaceAll(";;;;;", ";");
message = message.replaceAll(";;;", ";");
message = message.replaceAll(";;", ";");
String[] splitted2 = message.split(";");

char someChar = ';';
int count = 0;

if (message.length()>5) {
for (int i = 0; i < message.length(); i++) {
if (message.charAt(i) == someChar) {
if (count == 0) txtA1.setText(splitted2[0]);
if (count == 1) txtA2.setText(splitted2[1]);
if (count == 2) txtB1.setText(splitted2[2]);
if (count == 3) txtB2.setText(splitted2[3]);
if (count == 4) txtC1.setText(splitted2[4]);
if (count == 5) txtC2.setText(splitted2[5]);
if (count == 6) txtD1.setText(splitted2[6]);
if (count == 7) txtD2.setText(splitted2[7]);

if (count == 8) txtE1.setText(splitted2[8]);
if (count == 9) txtE2.setText(splitted2[9]);
if (count == 10) txtF1.setText(splitted2[10]);
if (count == 11) txtF2.setText(splitted2[11]);
if (count == 12) txtG1.setText(splitted2[12]);
if (count == 13) txtG2.setText(splitted2[13]);
if (count == 14) txtH1.setText(splitted2[14]);
if (count == 15) txtH2.setText(splitted2[15]);

if (count == 16) txtI1.setText(splitted2[16]);
if (count == 17) txtI2.setText(splitted2[17]);
if (count == 18) txtJ1.setText(splitted2[18]);
if (count == 19) txtJ2.setText(splitted2[19]);

count++;
}
}
}
}
});

row2.addView(btnDefault, lp2);

final Button btnLoad = new Button(this);
btnLoad.setText("Cancel");
btnLoad.setTextSize(12);
btnLoad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences sharedPref;
sharedPref = getSharedPreferences("Selection", MODE_PRIVATE);
//String actualJoin = sharedPref.getString(getString(R.string.saved_links)+";;;;;;;;;;", "Info1;http://nanopedia.site/;Info2;http://ipedia.site/;Info3;http://telepedia.site/;Info4;http://www.quatrecoin.com/");

String actualJoin=sharedPref.getString(getString(R.string.saved_links), "");

String mTest=sharedPref.getString(getString(R.string.saved_links), "");

String[] splitted = actualJoin.split(";");
char someChar = ';';
int count = 0;

//splitted.length

//if (actualJoin.length()>5) {
// for (int i = 0; i < actualJoin.length(); i++) {
// if (actualJoin.charAt(i) == someChar) {
//if (count == 0)
if (splitted.length>0) txtA1.setText(splitted[0].concat(" "));
//if (count == 1)
if (splitted.length>1) txtA2.setText(splitted[1].concat(" "));
//if (count == 2)
if (splitted.length>2) txtB1.setText(splitted[2].concat(" "));
//if (count == 3)
if (splitted.length>3) txtB2.setText(splitted[3].concat(" "));
//if (count == 4)
if (splitted.length>4) txtC1.setText(splitted[4].concat(" "));
//if (count == 5)
if (splitted.length>5) txtC2.setText(splitted[5].concat(" "));
//if (count == 6)
if (splitted.length>6) txtD1.setText(splitted[6].concat(" "));
//if (count == 7)
if (splitted.length>7) txtD2.setText(splitted[7].concat(" "));

if (splitted.length>8) txtE1.setText(splitted[8].concat(" "));
//if (count == 9)
if (splitted.length>9) txtE2.setText(splitted[9].concat(" "));
//if (count == 10)
if (splitted.length>10) txtF1.setText(splitted[10].concat(" "));
//if (count == 11)
if (splitted.length>11) txtF2.setText(splitted[11].concat(" "));
//if (count == 12)
if (splitted.length>12) txtG1.setText(splitted[12].concat(" "));
//if (count == 13)
if (splitted.length>13) txtG2.setText(splitted[13].concat(" "));
//if (count == 14)
if (splitted.length>14) txtH1.setText(splitted[14].concat(" "));
//if (count == 15)
if (splitted.length>15) txtH2.setText(splitted[15].concat(" "));

//if (count == 16)
if (splitted.length>16) txtI1.setText(splitted[16].concat(" "));
//if (count == 17)
if (splitted.length>17) txtI2.setText(splitted[17].concat(" "));
//if (count == 18)
if (splitted.length>18) txtJ1.setText(splitted[18].concat(" "));
//if (count == 19)
if (splitted.length>19) txtJ2.setText(splitted[19].concat(" "));

txtMulti.setText(mTest);


//count++;
// }
// }
//}
}
});

row2.addView(btnLoad, lp2);

Button btnSave = new Button(this);
btnSave.setText("Save");
btnSave.setTextSize(12);

btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//mainF();
SharedPreferences sharedPref = getSharedPreferences("Selection", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
String message1 = txtA1.getText()+";"+txtA2.getText()+";"+txtB1.getText()+";"+txtB2.getText()+";"+txtC1.getText()+";"+txtC2.getText()+";"+txtD1.getText()+";"+txtD2.getText()+";"+txtE1.getText()+";"+txtE2.getText()+";"+txtF1.getText()+";"+txtF2.getText()+";"+txtG1.getText()+";"+txtG2.getText()+";"+txtH1.getText()+";"+txtH2.getText()+";"+txtI1.getText()+";"+txtI2.getText()+";"+txtJ1.getText()+";"+txtJ2.getText();
editor.putString(getString(R.string.saved_links), message1);
editor.apply();
}

});
row.addView(btnSave, lp2);


buttonsView.addView(row, lpW);

buttonsView.addView(row3, lpW);
buttonsView.addView(row4, lpW);
buttonsView.addView(row5, lpW);
buttonsView.addView(row6, lpW);

buttonsView.addView(row2, lpW);

buttonsView.addView(row7, lpW);

addContentView(buttonsView, lpW);
}


public void openActivity1() {
Intent intent = new Intent(this, MainActivity.class );
startActivity(intent);
}

}

4. В файле main_menu.xml удалите все строки и вставьте:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_sc10"
android:title="@string/menu_sc10" />
<item android:id="@+id/menu_sc25"
android:title="@string/menu_sc25" />
<item android:id="@+id/menu_sc50"
android:title="@string/menu_sc50" />
<item android:id="@+id/menu_sc100"
android:title="@string/menu_sc100" />
<item android:id="@+id/menu_sc150"
android:title="@string/menu_sc150" />
<item android:id="@+id/menu_sc200"
android:title="@string/menu_sc200" />
<item android:id="@+id/menu_sc300"
android:title="@string/menu_sc300" />
<item android:id="@+id/menu_clear"
android:title="@string/menu_clear" />
</menu>

5. В файле strings.xml удалите все строки и вставьте:

<resources>
<string name="app_name">DigestViewer</string>
<string name="menu_sc10">10%</string>
<string name="menu_sc25">25%</string>
<string name="menu_sc50">50%</string>
<string name="menu_sc100">100%</string>
<string name="menu_sc150">150%</string>
<string name="menu_sc200">200%</string>
<string name="menu_sc300">300%</string>
<string name="menu_clear">ClearUserLinks</string>
<string name="saved_scale">save_high</string>
<string name="saved_links">saved_links</string>
</resources>

Теперь можно запускать программу и менять через кнопку Settings пользовательские ссылки (сначала их нужно ввести/вставить в нижнее текстовое поле, а потом нажать кнопку User Links), например:

Info1
http://nanopedia.site/
Info2
http://ipedia.site/
Info3
http://telepedia.site/
Info4
http://www.quatrecoin.com/
Info5
http://rambler.ru/
Info6
http://yandex.ru/
Info7
http://google.com/
Info8
http://www.tablepedia.com/
Info9
http://paleomag.ru/
Info10
http://www.hashtagchain.org/