use DecimalFormat into Textview on the TextWatcher - listener

I want use DecimalFormat into Textview on the TextWatcher
I want (TextView) change format to decimalformat and show on the activity
thank you

Related

How to add positioning in when calling JSONobject in JSON arrray

Here is my code
Main .java file :
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
ListView lv;
ArrayAdapter<String> adapter;
ArrayList<String> arr;
JSONObject object=new JSONObject();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView)findViewById(R.id.lv1);
arr = new ArrayList<>();
arr.add("Dedicated To.. ");
arr.add("1. A cheerful heart");
arr.add("2. A new commandment");
arr.add("3. A pure heart");
try {
object.put("1. A cheerful heart"," you ");
object.put("2. A new commandment","Welcome");
object.put("2. A new commandment","Welcome");
object.put("3. A pure heart","Heis");
} catch (JSONException e) {
e.printStackTrace();
}
final JSONArray keys=object.names();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i=new Intent(MainActivity.this,Main2Activity.class);
try {
i.putExtra("text",object.getString(keys.getString(position)));
} catch (JSONException e) {
e.printStackTrace();
}
startActivity(i);
}
});
There some other code to too.
My Doubt is,
Here if you see arr.add("1. A cheerful heart"); is the one which I am passing to object.put("1. A cheerful heart"," you ");.
When I click on Cheerful heart item it should show you on its respectively but it is taking a random value which like object.put("3. A pure heart","Heis"); i.e; value is passing randomly. IF there are 100 it is taking random values.
So I need help to give positioning When I click on item1 it has to give item1 content in next activity. When I click item2 it should give me Item2 content respectively.
Please, someone, help me how to give positioning when I passing JSON array to JSON object. Also If any help me with Search view integrated into my question well appreciated.
IF loop or for loop is fine, I want I give full code.

How to set JSONArray in model attribute in spring modelandview controller?

I want to add JSONArray in spring's model attribute and return from ModelAndView Controller. Not able to do like below. Request for help. Thanking you!
#RequestMapping(value = "/sample.htm", method = RequestMethod.GET)
public ModelAndView seatRequest( ModelMap model,
HttpServletRequest request,HttpServletResponse response, HttpSession session) throws JSONException, JsonProcessingException {
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
jsonObject.put("0", "val0");
jsonObject.put("1", "val1");
jsonObject.put("2", "val2");
jsonArray.put(jsonObject);
model.addAttribute("jsonData",jsonArray.toString());
return new ModelAndView("sample");
What is your intention? Currently JsonArray is added in String form.You can access this jsonArray as a String in your view. But I think you don't want to do that. If you want to access it as object just add as model.addAttribute("jsonData",jsonArray) and then you can access it as object in your views.
Also, In your json Object, Key value is Numric "0","1" so on. make it alphanumeric i.e "key1", "key2" etc. and values "val1","val2" etc. Because name of identifiers cannot start with numbers.

Listview item background color change

I want to change the list-view item background color without onitemclick() method. Because at first i've to check item data and based on that it will change the color . How should i do it ?
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view, int position,
long id) {
if(items.get(position).getSomething().equals(Something){
// If your condition fulfills then change background color
listView.getChildAt(position).setBackgroundColor(#55667788);
}
}
});
EDIT:
#Override
public View getView(final int position, View convertView, ViewGroup arg2) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater inflater = context.getLayoutInflater();
convertView = inflater.inflate(R.layout.row_counter, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.name = (TextView) convertView.findViewById(R.id.tv_name);
viewHolder.number = (TextView) convertView
.findViewById(R.id.tv_number);
viewHolder.row = (TextView) convertView
.findViewById(R.id.rel_row);
convertView.setTag(viewHolder);
}
holder = (ViewHolder) convertView.getTag();
currentModel = list.get(position);
holder.name.setText(currentModel.getName());
holder.number.setText(currentModel.getNumber());
if(holder.name.equals("SOMETHING")){
holder.row.setBackgroundColor("#55667788");
}else{
holder.row.setBackgroundColor("#000000");
}
return convertView;
}

Add view created dynamically to convertview in expandable listview android

This is my first question, I need to add dynamically textViews to convertView that is returned in getChildView() method expandable, but I can not do in any way..
#Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ViewHolderChild holder;
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.child_line, null);
holder = new ViewHolderChild();
holder.txNumeroSolicitacao = (TextView) convertView.findViewById(R.id.textViewNumeroSolicitacao);
convertView.setTag(holder);
} else {
holder = (ViewHolderChild) convertView.getTag();
}
holder.txNumeroSolicitacao.setText(String.valueOf(getChild(groupPosition,childPosition).getNumero()));
//if my log list isn't empty, I want add a textview dynamically to view
if(!getChild(groupPosition,childPosition).getLog().isEmpty()) {
holder.textViewResponse = new TextView(context);
RelativeLayout.LayoutParams alignParentLeft = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
alignParentLeft.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
holder.textViewResponse.setLayoutParams(alignParentLeft);
((ViewGroup) convertView).addView(holder.textViewResponse);
}
return convertView;
}
But I can not add the textView to convertView. The application always returns unexpected behaviour.
You might add the TextView in child_line.xml with android:visibility="gone", and set it's visibility in getChildView according to if the current line's bound object's log is empty.

MONOTOUCH get row item selected

I have a navigation controller to show a list o item on table, then I need to touch an item a show the details of this item.
Here it's my code of how a fill the table:
public void SearchHotel (){
Hotel hotel = new Hotel();
var distribution = new HotelDistribution[]{new HotelDistribution(){ Adults = 1, Children = 0, ChildrenAges = new int[0]} };
var items = hotel.SearchHotels(Convert.ToDateTime("2013-08-08"),Convert.ToDateTime("2013-09-09 "),"(MIA)", distribution,"","","",0);
data = new List<DtoHotelinformation>();
foreach (var item in items)
{
DtoHotelinformation DtoHotelinformation = new DtoHotelinformation();
DtoHotelinformation.code = item.Code.ToString();
DtoHotelinformation.price = item.Price.ToString();
DtoHotelinformation.title = item.Name.ToString().ToTitleCase();
DtoHotelinformation.subtitle = item.Address.ToString();
DtoHotelinformation.rating = item.Rating.ToString();
DtoHotelinformation.imageUlr = item.ImageUrl;
data.Add(DtoHotelinformation);
}
hud.Hide(true);
hud.RemoveFromSuperview();
HotelSearchTable.Source = new HotelTableSource(data.ToArray());
HotelSearchTable.ReloadData();
}
Because I'm using storyboard to show the details view controller I have this code on my table source:
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
if (RowTouched != null) {
RowTouched (this, EventArgs.Empty);
}
tableView.DeselectRow (indexPath, true); // normal iOS behaviour is to remove the blue highlight
}
Back in to my viewcontroller I call the RowTouched to show the details controller like this:
public override void ViewDidAppear (bool animated) {
base.ViewDidAppear (animated);
SearchHotel ();
var source = new HotelTableSource(data.ToArray());
var detail = Storyboard.InstantiateViewController("HotelDetailScreen") as iPhoneHotelDetailViewController;
source.RowTouched += (sender, e) => {
this.NavigationController.PushViewController(detail, true);
};
HotelSearchTable.Source = source;
}
But I need to pass the information of the item touched on the table to show the details. I don't really don't know what do I have to do?
NOTE: I can't use PrepareForSegue because I don't have a segue between controllers.
Thanks in advance
If you want you can get a hold of your UINavigationController
from within your Row Selected event, inside of your Table Data Source.
From there you can push your new ViewController.
[indexPath.Row] in "Row_Selected" should tell you which element in your array or list, that the user has selected.
UINavigationController navcontroller =(UINavigationController)UIApplication.SharedApplication.Windows[0].RootViewController;
Passing data to an event handler is exatly what the EventArgs parameter is for.
Create a class that inherits from EventArgs and has properties for the data you need:
public class HotelSelectedEventARgs : EventArgs
{
public DTOHotelInformation HotelInfo { get; set; }
}
Then, when you call your handler in RowSelected, instead of passing an empty EventArgs, create an instance of your custom class and assign the selected data to the HotelInfo property.