我是android的新手,在我的应用程序中我使用了json,我正在获得产品的价格,我正在尝试添加印度卢比符号,但它没有显示............. ...........
Tab1Activity.java
public class Tab1Activity extends ListActivity{
private ProgressDialog pDialog;
JSONArray Product=null;
private ListView listview;
ArrayList<HashMap<String,String>> aList;
ArrayList<HashMap<String, String>> arrayTemplist;
private static String PRODUCT_URL = "";
private static final String PRODUCT_DATA="Product";
private static final String PRODUCT_ID="productid";
private static final String PRODUCT_NAME="product_name";
private static final String PRODUCT_CODE="skucode";
private static final String PRODUCT_IMAGE="product_photo";
private static final String PRODUCT_WEIGHT="weight";
private static final String PRODUCT_SALERATE="sale_rate";
private CustomAdapterTabone adapter;
private TextView noacpt;
private AutoCompleteTextView inputSearch;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view_tabone);
//noacpt=(TextView)findViewById(R.id.no_acceptedlist);
/*String strtext = getIntent().getStringExtra("id");
System.out.println("<<<<<<<< id : " + strtext);*/
//INTEREST_ACCEPT_URL = "
ListView listview = (ListView)findViewById(android.R.id.list);
//listview.setSelector( R.drawable.list_selector);
//listview.setSelector(R.drawable.listselector);
new LoadAlbums().execute();
aList = new ArrayList<HashMap<String, String>>();
final ListView lv = getListView();
inputSearch = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
arrayTemplist= new ArrayList<HashMap<String,String>>();
String searchString =inputSearch.getText().toString().toLowerCase();
for (int i = 0; i < aList.size(); i++)
{
String currentString =aList.get(i).get(Tab1Activity.PRODUCT_NAME);
if (currentString.toLowerCase().startsWith(searchString ))
{
arrayTemplist.add(aList.get(i));
}
}
for (int i = 0; i < arrayTemplist.size(); i++)
{
String currentstrin = arrayTemplist.get(i).get(Tab1Activity.PRODUCT_NAME);
//Toast.makeText(getApplicationContext(), currentstrin, Toast.LENGTH_LONG).show();
}
CustomAdapterTabone adapter=new CustomAdapterTabone(getApplicationContext(), arrayTemplist);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Intent intent = new Intent(getApplicationContext(), Tab1Activity.class);
intent.putExtra("interestaccept_user_id", aList.get(position).get(PRODUCT_ID));
startActivity(intent);
}
class LoadAlbums extends AsyncTask<String, String, ArrayList<HashMap<String,String>>> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Tab1Activity.this);
pDialog.setMessage("Loading...");
pDialog.setIndeterminate(true);
// pDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.custom_progress));
pDialog.setCancelable(false);
pDialog.show();
}
protected ArrayList<HashMap<String,String>> doInBackground(String... args) {
ServiceHandler sh = new ServiceHandler();
// Making a request to url and getting response
ArrayList<HashMap<String,String>> data = new ArrayList<HashMap<String, String>>();
String jsonStr = sh.makeServiceCall(PRODUCT_URL, ServiceHandler.GET);
Log.d("Response: ", "> " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
Product = jsonObj.getJSONArray(PRODUCT_DATA);
for (int i = 0; i < Product.length(); i++) {
JSONObject c = Product.getJSONObject(i);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(PRODUCT_ID, c.getString(PRODUCT_ID));
map.put(PRODUCT_NAME,c.getString(PRODUCT_NAME));
map.put(PRODUCT_CODE, c.getString(PRODUCT_CODE));
map.put(PRODUCT_IMAGE, c.getString(PRODUCT_IMAGE));
map.put(PRODUCT_WEIGHT, c.getString(PRODUCT_WEIGHT));
map.put(PRODUCT_SALERATE, c.getString(PRODUCT_SALERATE)+getResources().getString(R.string.rupee));
// map.put(INTEREST_ACCEPT_LOCATION, c.getString(INTEREST_ACCEPT_LOCATION));
// adding HashList to ArrayList
data.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return data;
}
protected void onPostExecute(ArrayList<HashMap<String,String>> result) {
super.onPostExecute(result);
if(Product == null || Product.length() == 0){
Toast.makeText(getApplicationContext(), "No response", Toast.LENGTH_SHORT).show();
//noacpt.setText(" No Accepted List ");
}
else
{
//noacpt.setVisibility(View.INVISIBLE);
}
// dismiss the dialog after getting all albums
if (pDialog.isShowing())
pDialog.dismiss();
if(aList == null){
aList = new ArrayList<HashMap<String, String>>();
aList.addAll(result);
adapter = new CustomAdapterTabone(getApplicationContext(),result);
setListAdapter(adapter);
}else{
aList.addAll(result);
adapter.notifyDataSetChanged();
}
}
}
使用此行:
map.put(PRODUCT_SALERATE, c.getString(PRODUCT_SALERATE)+getResources().getString(R.string.rupee));
我正在获得输出
但是我想要这样的东西
答案 0 :(得分:1)
尝试在哈希映射中的金额之前添加卢比符号:
map.put(PRODUCT_SALERATE, getResources().getString(R.string.rupee) + c.getString(PRODUCT_SALERATE));
检查讨论后Chat
,我认为这是缺少部分