How to add indian rupee symbol?

2019-03-04 23:43发布

问题:

I am new to android,In my application I used json,and I am getting price of product and I am trying to add indian rupee symbol,but its not showing........................

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();
    }
}

}

Using this line :

  map.put(PRODUCT_SALERATE, c.getString(PRODUCT_SALERATE)+getResources().getString(R.string.rupee));

I am getting follwing output

but I want something like this

回答1:

Try adding the Ruppee symbol before the amount in hash map :

map.put(PRODUCT_SALERATE, getResources().getString(R.string.rupee) + c.getString(PRODUCT_SALERATE));

After checking discussion Chat

, I think this is missing part