java — арабские символы не распознаются

Я извлекаю текст из базы данных в Android Studio, используя Java и PHP. Тексты на английском языке отображаются успешно, однако, когда я добавляю арабский в базу данных, он отображается в Android как поля. Ребята, пожалуйста, помогите мне разобраться с этим.

это прекрасно работает на странице браузера HTML. но в андроиде его нет. Однако его XML-файл установлен в UTF8. это должно работать. Может кто-нибудь выяснить проблему?

Main.java

  public class Main extends AppCompatActivity {
//phpconnection declaration
TextView resultView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//phpconnection starts from here

StrictMode.enableDefaults();

resultView = (TextView) findViewById(R.id.textView);

getData();
//button

Button insert=(Button) findViewById(R.id.button);

insert.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
// TODO Auto-generated method stub

getData();
}
});
//phpconnection ends here
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}



//phpconnection again starts
public void getData() {
String result = "ERROR!\n Please turn on mobile data or Wi-Fi in settings";
InputStream isr = null;

try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost ("http://balochplay.zz.mu/test/index.php");
HttpResponse response = httpclient.execute (httppost);
HttpEntity entity = response.getEntity();
isr = entity.getContent();
}
catch(Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
resultView.setText("Couldn't connect to database");
}

//convert response to string

try {
BufferedReader reader = new BufferedReader(new InputStreamReader(isr,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
isr.close();

result=sb.toString();
}
catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}

//parse json data
try {
resultView.setText(result);
}
catch(Exception e) {
Log.e("log_tag", "Couldn't set text.");
}

}

activity_main.xml

   <TextView
android:layout_width="fill_parent"android:layout_height="match_parent"android:singleLine="false"android:id="@+id/textView"android:text="Error! \nPlease Connect to Internet"android:gravity="center"android:textAlignment="center"android:layout_below="@+id/imageView3"android:textColor="#ffffff"android:textSize="25sp"android:autoText="false"android:typeface="monospace"android:layout_above="@+id/button"android:layout_alignParentRight="true"android:layout_alignParentEnd="true"android:nestedScrollingEnabled="false"android:focusable="true"android:layout_marginTop="20dp" />

пожалуйста, покажите мне, как это исправить.

Я видел другие подобные вопросы на форуме, которые я пытался, но у меня не получилось.


Мои настройки базы данных:

Сортировка таблицы utf8_general_ci и его тип MyISAMи столбцы (id, name) внутри него: тип int для id а также средний текст для имени и сопоставление utf8_general_ci

ех. вывод должен быть السلام عليكم, но это ¨ „ببي

phpcode

дп

<?php
//create connection
$con=mysqli_connect    ("mysql.hostinger.ph","u242667358_abc","123456","u242667358_test");


//check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

?>

индекс

<?php
header('Content-Type: text/html; charset=utf-8');

require_once('db.php');

$query = "SELECT * FROM BalochiNames ORDER BY RAND() LIMIT 1";

$result = mysqli_query($con, $query);

while ($row = mysqli_fetch_array($result)) {

echo stripslashes($row['BalochiName']);

}

?>

1

Решение

Попробуй это Арабский язык в Android

Он имеет полное руководство, как показать арабский язык в Android.

Также вам нужно включить несколько классов в ваш проект Android, учитывая Вот.
Следуйте инструкциям, и вы будете знать, что делать.

Простой пример

AssetManager manager=this.getAssets();
manager.open("tahoma.ttf");
TextView tv=(TextView)this.findViewById(R.id.textView);
tv.setTypeface(Typeface.createFromAsset(manager, "tahoma.ttf"));
tv.setTextSize(50f);
tv.setText(ArabicUtilities.reshape(" الحمد لله hello"));
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector