我正在制作一个特定于语言的应用程序,用户可以从列表中选择语言(印地语或英语)。
当用户选择英语时,一切都运行良好,即用户将数据插入数据库,然后在文本字段中正确检索,但当用户选择印地语并用印地语将数据插入数据库时,显示文本字段价值为" ??????"
我想要的是文本字段值必须用印地语显示.. 我已经使用了Typeface但这不起作用 这是我的代码部分
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/hindi.ttf"); //i have put hindi.ttf file in fonts folder under assets under main
name.setTypeface(tf);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (view.getId() == R.id.tvsave) {
if (name.getText().toString().length() == 0) {
name.setError("Name cannot be empty");
} else if (phone.getText().toString().length() == 0) {
phone.setError("Phone No. cannot be empty");
}
else if(!phone.getText().toString().matches(phonePattern))
phone.setError("Invalid Mobile");
} else if (house.getText().toString().length() == 0) {
house.setError("House No. cannot be empty");
} else if (area.getText().toString().length() == 0) {
area.setError("Area cannot be empty");
} else if (landmark.getText().toString().length() == 0) {
landmark.setError("Landmark cannot be empty");
} else if
(name.getText().toString().length() == 0 || phone.getText().toString().length() == 0 || house.getText().toString().length() == 0 || area.getText().toString().length() == 0 || landmark.getText().toString().length() == 0) {
Toast.makeText(getApplicationContext(), "Please Enter Details",
Toast.LENGTH_LONG).show();
} else if (Utils.isNetworkAvailable(AddNewAddress.this)) {
new saveaddress().execute(custid, name.getText().toString(), phone.getText().toString(), house.getText().toString(), landmark.getText().toString(), datamodel.getId(), area.getText().toString()); //this is saving data into database
} else {
final Dialog dialog = new Dialog(AddNewAddress.this);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
dialog.setContentView(R.layout.internetconnectiondialog);
dialog.setTitle(AddNewAddress.this.getResources().getString(R.string.connectionfailed));
TextView text = (TextView) dialog.findViewById(R.id.textDialog);
text.setText(AddNewAddress.this.getResources().getString(R.string.checkinternetsettings));
dialog.show();
Button declineButton = (Button) dialog.findViewById(R.id.declineButton);
declineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
}
}
});
mySpinner = (Spinner) findViewById(R.id.spncity);
new spinnercity().execute(language);
}
class saveaddress extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
dialogFrag.show(getSupportFragmentManager(), "Dialog");
dialogFrag.setCancelable(false);
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
JSONObject jsonObject;
try {
String response = AddNewAddressPostHit.getJSONfromURL(params[0], params[1], params[2], params[3], params[4], params[5], params[6]);
jsonObject = new JSONObject(response.toString());
message = jsonObject.getString("Msg");
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
dialogFrag.dismiss();
super.onPostExecute(result);
}
当用户将数据插入text_fields
语言Hindi
时,我希望这些Hindi
值必须以English
语言显示
我已经使用Typeface
但这不起作用。
尽快告诉我我错在哪里。
答案 0 :(得分:0)
尝试使用此方法转换字符串数据,同时保存到db,同时从db中获取这些数据。
String str = (URLDecoder.decode(your_editext_value, "UTF-8"));