Get all edittext values which are inflating in loop in android - android

Hello I am inflate xml file like..
List<EditText> allEds3 = new ArrayList<EditText>();
LayoutInflater inflater = inflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int hh1 = 57; hh1 <= 76; hh1++) {
try {
View view = inflater.inflate(R.layout.form6, null);
form6_linear.addView(view);
lbl1 = (TextView) view.findViewById(R.id.lbl1);
lbl2 = (TextView) view.findViewById(R.id.lbl2);
txt1 = (TextView) view.findViewById(R.id.txt1);
txt1.setId(hh1);
txt1.setText(txt_array.get(hh1));
txt1.setOnClickListener(onclicklistener);
_txt2 = (EditText) view.findViewById(R.id.txt2);
lbl1.setText(lbl_array.get(hh1));
lbl2.setText(lbl_array.get(hh1 + 1));
_txt2.setText(txt_array.get(hh1 + 1));
allEds3.add(_txt2);
hh1++;
nn1++;
} catch (Exception e) {
// TODO: handle exception
}
}
Now I have one button in my main xml file and onclick of that button I have to get all values of this _txt2 of above.
Please help.
EDIT:
List<EditText> allEds3 = new ArrayList<EditText>();
LayoutInflater inflater = inflater = (LayoutInflater) getApplicationContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int hh1 = 57; hh1 <= 76; hh1++) {
try {
View view = inflater.inflate(R.layout.form6, null);
form6_linear.addView(view);
lbl1 = (TextView) view.findViewById(R.id.lbl1);
lbl2 = (TextView) view.findViewById(R.id.lbl2);
txt1 = (TextView) view.findViewById(R.id.txt1);
txt1.setId(hh1);
txt1.setText(txt_array.get(hh1));
txt1.setOnClickListener(onclicklistener);
_txt2 = (EditText) view.findViewById(R.id.txt2);
lbl1.setText(lbl_array.get(hh1));
lbl2.setText(lbl_array.get(hh1 + 1));
_txt2.setText(txt_array.get(hh1 + 1));
allEds3.add(_txt2);
hh1++;
nn1++;
} catch (Exception e) {
// TODO: handle exception
}
}
OnClick()
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_continue1:
final String[] strings2 = new String[allEds3.size()];
for (int i = 0; i < allEds3.size(); i++) {
strings2[i] = allEds3.get(i).getText().toString();
}
int ii = 0;
for (int db = 57; db <= 76; db++) {
try {
j.remove(txt_array.get(db));
j.put(txt_array.get(db), strings2[ii]);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ii++;
}
}
}
Error :-
ArrayIndexOutOfBounds at
j.put(txt_array.get(db), strings2[ii]);

If _txt2 is defined as a field in your activity class, then you can simply get it on the button's onClick:
// in onCreate block of your activity
Button button = (Button) findViewById(R.id.button_to_click);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
// here you can do anything with _txt2 which is just executed when button is clicked
}
}
EDIT: I didn't figure out your question properly, so I should add this:
You can set an ID to any EditText you create. then find them by findViewById() when needed. or you can store all EditText(s) in an array of EditText and get them later.

Related

select the checked item from listview on popup window and show these selected items on that activity screen in android

I am a new to android BaseAdapter and I am facing a null pointer exception when get the checked item from popup window.
what I want to do given below-
I want to select the checked item from checked listview on popup window and show these selected items on that activity screen when the popup window has gone.
here is my code-
Dropdownlist.java
private void initialize(){
//data source for drop-down list
// final ArrayList<String> itemlist = new ArrayList<String>();
checkSelected = new boolean[itemlist.size()];
//initialize all values of list to 'unselected' initially
for (int i = 0; i < checkSelected.length; i++) {
checkSelected[i] = false;
}
enter code here
final TextView tv = (TextView) findViewById(R.DropDownList.SelectBox);
tv.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
int len = list.getCount();
SparseBooleanArray checked = list.getCheckedItemPositions();
str=Integer.toString(checked.size());
for (int i = 0; i < len; i++) {
str=Integer.toString(len);
// Item position in adapter
if (checked.get(i)) {
item += itemlist.get(i);
//item += adapter.getItem(i).toString();
selectedItems.add(item);
/*do whatever you want with the checked item */
}
//int position = checked.keyAt(i);
selectedItems.add(adapter.getItem(position).toString());
}
outputStrArr = new String[selectedItems.size()];
for (int i = 0; i < selectedItems.size(); i++) {
outputStrArr[i] = selectedItems.get(i);
}
Toast.makeText(getApplicationContext(), str, Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(),
ResultActivity.class);
// Create a bundle object
Bundle b = new Bundle();
b.putStringArray("selectedItems", outputStrArr);
// Add the bundle to the intent.
intent.putExtras(b);
// start the ResultActivity
startActivity(intent);
}
});
//onClickListener to initiate the dropDown list
Button createButton = (Button)findViewById(R.DropDownList.create);
createButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
initiatePopUp(itemlist,tv);
}
});
}
private void initiatePopUp(ArrayList<String> itemlist, TextView tv){
LayoutInflater inflater = (LayoutInflater)DropDownListDemo.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//get the pop-up window i.e. drop-down layout
LinearLayout layout = (LinearLayout)inflater.inflate(R.layout.pop_up_window, (ViewGroup)findViewById(R.id.PopUpView));
//get the view to which drop-down layout is to be anchored
RelativeLayout layout1 = (RelativeLayout)findViewById(R.id.relativeLayout1);
pw = new PopupWindow(layout, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, true);
//Pop-up window background cannot be null if we want the pop-up to listen touch events outside its window
pw.setBackgroundDrawable(new BitmapDrawable());
pw.setTouchable(true);
//let pop-up be informed about touch events outside its window. This should be done before setting the content of pop-up
pw.setOutsideTouchable(true);
pw.setHeight(LayoutParams.WRAP_CONTENT);
//dismiss the pop-up i.e. drop-down when touched anywhere outside the pop-up
pw.setTouchInterceptor(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
pw.dismiss();
return true;
}
return false;
}
});
//provide the source layout for drop-down
pw.setContentView(layout);
//anchor the drop-down to bottom-left corner of 'layout1'
pw.showAsDropDown(layout1);
//populate the drop-down list
list = (ListView) layout.findViewById(R.DropDownList.dropDownList);
adapter = new DropDownListAdapter(this, itemlist, tv);
list.setAdapter(adapter);
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
Here is DropDownListAdapter class extends Base adapter
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
convertView = mInflater.inflate(R.layout.drop_down_list_row, null);
holder = new ViewHolder();
holder.tv = (TextView) convertView.findViewById(R.DropDownList.SelectOption);
holder.chkbox = (CheckBox) convertView.findViewById(R.DropDownList.checkbox);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.tv.setText(mListItems.get(position));
final int position1 = position;
//whenever the checkbox is clicked the selected values textview is updated with new selected values
holder.chkbox.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
setText(position1);
}
});
if(DropDownListDemo.checkSelected[position])
holder.chkbox.setChecked(true);
else
holder.chkbox.setChecked(false);
return convertView;
}

Scrolling the ListView sets colors to all the buttons that do not satisfy the conditions in getview method of SimpleAdapter

I have implemented a ListView using SimpleAdapter in Android. I have set certain conditions in the getView method of the SimpleAdapter.
According to the satisfied conditions the Buttons present in each row of the ListView will be turned to Red, Green, Yellow or Orange.
The problem I am encountering is that when I scroll the ListView up and down continously I can see that some Buttons that don't satisfy the conditions are also changing the colors and at the end all the Buttons have the above mentioned color.
Can anyone suggest me where I am going wrong.My codes are as below:
BaseAdapter waiter_adapter = new SimpleAdapter(
getApplicationContext(), list_details_from_db,
R.layout.waiter_screen_details/* waiter_order_details */,
new String[] { "table_no", "order_id" }, new int[] {
R.id.tv_table_no, R.id.order_id }) {
#Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
/*final*/ View v = super.getView(position, convertView,
parent);
// Log.i("key values sub id in get view ",
// ""+key_names);
final TextView order_id = (TextView) v
.findViewById(R.id.order_id);
Log.i("Order id check from getview ", order_id
.getText().toString());
Button bt_waiter_id = (Button) v
.findViewById(R.id.bt_waiter_id);
Button placed_id = (Button) v
.findViewById(R.id.placed_id);
Button confirmed = (Button) v
.findViewById(R.id.confirmed);
Button prepared = (Button) v
.findViewById(R.id.prepared);
prepared.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String o_id = order_id.getText().toString();
Intent prep_list = new Intent(
Waiter_Order_List_ctivity.this,
Prep_List_activity.class);
prep_list.putExtra("Order_Id", o_id
/* order_id_to_intent */);
Log.i("Order id sent to Prep list", o_id /* order_id_to_intent */);
startActivity(prep_list);
}
});
confirmed.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
final String order_id_str = order_id.getText()
.toString();
ArrayList<HashMap<String, String>> data = db
.get_order_course_list(order_id_str);
ArrayList<HashMap<String, String>> c = db
.get_item_status(order_id_str);
// if(item_status_from_db.get(index))
Log.i("item status retrievd from db", "" + c);
Log.i("database retrieved values from order course list",
"" + data);
Log.i("data size", "" + data.size());
try {
placed_id.setText(data.get(0).get("ist"));
confirmed.setText(data.get(0).get("confirm_ist"));
} catch (Exception e) {
e.printStackTrace();
}
try {
count = 0;
count_confirmed = 0;
count_processed = 0;
if (list_details_from_db.get(position)
.get("status")
.compareToIgnoreCase("Initial") == 0) {
bt_waiter_id.setBackground(getResources()
.getDrawable(
R.drawable.waitr_ordr_red_btn));
bt_waiter_id.setText("Waiter Id:"
+ "\n"
+ list_details_from_db.get(position)
.get("initial_status"));
} else {
for (int i = 0; i < data.size(); i++) {
String status_str = data.get(i).get(
"status1");
if (status_str
.compareToIgnoreCase("Placed") == 0) {
count++;
}
if (status_str
.compareToIgnoreCase("Confirmed") == 0) {
count_confirmed++;
}
if (status_str
.compareToIgnoreCase("Processed") == 0) {
count_processed++;
}
}
}
if (count > 0) {
placed_id
.setBackground(getResources()
.getDrawable(
R.drawable.waitr_ordr_yellow_btn));
}
if (count_confirmed > 0) {
confirmed
.setBackground(getResources()
.getDrawable(
R.drawable.waitr_ordr_orange_btn));
/*
* confirmed
* .setOnClickListener(Waiter_Order_List_ctivity
* .this);
*/
}
if (count_processed > 0) {
prepared.setBackground(getResources()
.getDrawable(
R.drawable.waitr_ordr_green_btn));
/*
* prepared.setOnClickListener(
* Waiter_Order_List_ctivity.this);
*/
}
if (c.size() > 0) {
prepared.setBackground(getResources()
.getDrawable(
R.drawable.waitr_ordr_green_btn));
}
} catch (Exception e) {
e.printStackTrace();
}
placed_id
.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intTableItm = new Intent(
Waiter_Order_List_ctivity.this,
Waiter_Confirm.class);
intTableItm.putExtra("Order_Id",
order_id_str);
startActivity(intTableItm);
}
});
return v;
}
};
w_order_list.setAdapter(waiter_adapter);
This depends on the reusage of the Listitems. If you change the Background in the if condition:
if (list_details_from_db.get(position)
You have to set it to the default background in the else condition.
//edit
#Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
/*final*/ View v = super.getView(position, convertView,
parent);
// Log.i("key values sub id in get view ",
// ""+key_names);
final TextView order_id = (TextView) v
.findViewById(R.id.order_id);
Log.i("Order id check from getview ", order_id
.getText().toString());
Button bt_waiter_id = (Button) v
.findViewById(R.id.bt_waiter_id);
Button placed_id = (Button) v
.findViewById(R.id.placed_id);
Button confirmed = (Button) v
.findViewById(R.id.confirmed);
Button prepared = (Button) v
.findViewById(R.id.prepared);
placed_id.setText("Your standard value");
confirmed.setText("Your standard value");
placed_id.setBackground(getResources()
.getDrawable(
R.drawable.your_standard_drawable));
confirmed.setBackground(getResources()
.getDrawable(
R.drawable.your_standard_drawable));
prepared.setBackground(getResources()
.getDrawable(
R.drawable.your_standard_drawable));
bt_waiter_id.setBackground(getResources()
.getDrawable(
R.drawable.your_standard_drawable));
bt_waiter_id.setText("your standard value");
//
//[...] Rest of your code
}

Remove the View from Layout of ScrollView

I have a ScrollView with LinearLayout into it.After adding the Layout into my LinearLayout, I wanted to remove the view but it removes only the first view.
I have tried parent.removeView(myView)
My Code for Layout adding :
LayoutInflater inflater = getLayoutInflater();
final View view_top = inflater.inflate(R.layout.layout_top, linear_layout,false);
final View view_bottom = inflater.inflate(R.layout.layout_bottom,linear_layout,false);
final RelativeLayout rel_layout_bottom = (RelativeLayout) view_bottom.findViewById(R.id.relative_bottom);
Button btn_update = (Button) rel_layout_bottom.findViewById(R.id.lst_todo_update);
ImageButton btn_remove = (ImageButton) rel_layout_bottom.findViewById(R.id.lst_btn_delete);
ImageButton btn_Color = (ImageButton) rel_layout_bottom.findViewById(R.id.lst_btn_color);
final RelativeLayout rel_layout_top = (RelativeLayout) view_top.findViewById(R.id.relative_top );
final TextView note_Title = (TextView) rel_layout_top.findViewById(R.id.lst_title );
final TextView note_color = (TextView) rel_layout_top.findViewById(R.id.lst_color_type );
note_Title.setText(note_title);
linear_layout.addView(rel_layout_bottom, 0);
JSONArray jsonArray=queryResult.getResultObjects().get(count).getJSONArray("todo_item");
for (int i = 0; i < jsonArray.length(); i++) {
final View view_middle = inflater.inflate(R.layout.layout_middle, linear_layout, false);
final RelativeLayout rel_layout_middle = (RelativeLayout) view_middle.findViewById(R.id.relative_middle);
final CheckBox note_check ;
final TextView note_content ;
note_content = (TextView) rel_layout_middle.findViewById(R.id.lst_content);
note_check = (CheckBox) rel_layout_middle.findViewById(R.id.lst_check);
btn_remove.setOnClickListener(null);
try {
//Getting data correctly here
linear_layout.addView(view_middle,0);
btn_remove.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
linear_layout.removeView(view_middle); //Not able to remove the view here i.e view_middle
linear_layout.removeView(view_top);
linear_layout.removeView(view_bottom);
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
linear_layout.addView(rel_layout_top , 0);
}
Any answer Appreciated...Thks
Something like below will solve your problem.
final View[] view_middleArr;
for (int i = 0; i < jsonArray.length(); i++) {
view_middleArr = new View[jsonArray.length()];
view_middleArr[i] = inflater.inflate(R.layout.layout_middle, linear_layout, false);
// ...
btn_remove.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
for (View view_middle : view_middleArr) {
linear_layout.removeView(view_middle);
}
linear_layout.removeView(view_top);
linear_layout.removeView(view_bottom);
}
});
}
Edit: You are using same view_middle reference for all your view_middle istances inside your loop, so you can only remove last view_middle instance with your code.
The code
btn_remove.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
linear_layout.removeView(view_middle); //Not able to remove the view here i.e view_middle
linear_layout.removeView(view_top);
linear_layout.removeView(view_bottom);
}
});
is in a for loop.
It means the click of the button will only remove the view_middle that was lastly added to the LinearLayout, as you are using the same object name.

Get value of textview after Inflating in Android

I am inflating the passenger_details_layout in main_passenger_details_layout.At run time i am setting the values in TextView . I am setting up pax_id that is invisible for every row that i am inflating in it.So on click of passenger_details_layout i want to call a new activity and pass the pax_id to the new activity.
Pax_id will be like 1,2,3 for every time for loop will run.So on click of 1 row i want to get the pax_id of first row that i have set.
Please help how could i do this Will be thank full to you.
Code to Infalate
ItinResponse data = obj.parseXMLData(fXmlFile);
List<SectorRecords> sectorList = data.getSectorRecordsDetails();
int items = 0;
List<PassengerDetails> listdata = data.getPaxDetails();
int i = 0;
for (PassengerDetails elements : listdata) {
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout layout = (RelativeLayout) inflater.inflate(
R.layout.passenger_details_layout, main, false);
firstName = (TextView) layout.findViewById(R.id.first_pax_name);
pax_id = (TextView) layout.findViewById(R.id.pax_id);
firstName.setText(elements.getFirstName() + " "
+ elements.getLastName());
pax_id.setText(elements.getPaxId());
main.addView(layout, i);
i++;
layout.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)"+pax_id.getText(), Toast.LENGTH_LONG).show();
}
});
On every row is showing the last pax id
You have to do nothing what you are trying
Replace this
pax_id.setText(elements.getPaxId());
to
layout.setId(Integer.parseInt(elements.getPaxId()));
And in your Layout Click
layout.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)"+layout.getId(), Toast.LENGTH_LONG).show();
}
});
Every time you will get the Unique ID that u want to set
All the best...!!!!
Use
TextView paxView = (TextView)v.findViewById(R.id.pax_id);
String pax_value = paxView.getText().toString();
On button click of every row do like this
Intent intent=new Intent(this,YOUR_NEXT_ACTIVIY.class);
intent.putExtra("paxid", pax_id.getText());
startActivity(intent);
ItinResponse data = obj.parseXMLData(fXmlFile);
List<SectorRecords> sectorList = data.getSectorRecordsDetails();
int items = 0;
List<PassengerDetails> listdata = data.getPaxDetails();
int i = 0;
for (PassengerDetails elements : listdata) {
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout layout = (RelativeLayout) inflater.inflate(
R.layout.passenger_details_layout, main, false);
firstName = (TextView) layout.findViewById(R.id.first_pax_name);
pax_id = (TextView) layout.findViewById(R.id.pax_id);
firstName.setText(elements.getFirstName() + " "
+ elements.getLastName());
pax_id.setText(elements.getPaxId());
layout.setTag(elements.getPaxId());
main.addView(layout, i);
i++;
layout.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
String paxId = v.getTag().toString();
// do some staff
}
});
}
// try this
ItinResponse data = obj.parseXMLData(fXmlFile);
List<SectorRecords> sectorList = data.getSectorRecordsDetails();
int items = 0;
List<PassengerDetails> listdata = data.getPaxDetails();
int i = 0;
for (PassengerDetails elements : listdata) {
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout layout = (RelativeLayout) inflater.inflate(
R.layout.passenger_details_layout, main, false);
firstName = (TextView) layout.findViewById(R.id.first_pax_name);
pax_id = (TextView) layout.findViewById(R.id.pax_id);
firstName.setText(elements.getFirstName() + " "
+ elements.getLastName());
pax_id.setText(elements.getPaxId());
layout.setTag(elements);
main.addView(layout, i);
i++;
layout.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
PassengerDetails elements = (PassengerDetails) v.getTag();
Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)"+elements.getPaxId(), Toast.LENGTH_LONG).show();
}
});
}

Android DatePicker Typeface

I am aware you can apply a custom TypeFace to a TextView in Android like this:
TextView tv = findViewById(R.id.textview01);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/BLACKROSE.TTF");
tv.setTypeface(tf);
Is there any way possible to do this for a DatePicker?
Here is my code. I hope it will be useful to someone.
DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker1);
LinearLayout layout1 = (LinearLayout) datePicker.getChildAt(0);
LinearLayout layout = layout1.getChildAt(0);
// day
LinearLayout day = (LinearLayout) layout.getChildAt(0);
setNumberPicker(day);
// month
LinearLayout month = (LinearLayout) layout.getChildAt(1);
setNumberPicker(month);
// year
LinearLayout year = (LinearLayout) layout.getChildAt(2);
setNumberPicker(year);
...
private void setNumberPicker(LinearLayout ll) {
((ImageButton) ll.getChildAt(0)).setBackgroundResource(R.drawable.plus_button);
((ImageButton) ll.getChildAt(2)).setBackgroundResource(R.drawable.minus_button);
EditText et = (EditText) ll.getChildAt(1);
et.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
et.setTypeface(youtTypeface);
}
After taking a look at the source, the Datepicker widget holds 3 NumberPicker widgets (for day, month, year)which in turn hold a TextView. So you are going have to set the Typeface for the TextView inside the NumberPickers inside the DatePicker.
I think you'll have to get the source for both NumberPicker and DatePicker and modify the source to achieve this, easier said than done I'm afraid.
Here is my solution:
private void overrideFonts(View v) {
ViewGroup picker;
try {
picker = (DatePicker) v;
} catch (Exception e) {
picker = (TimePicker) v;
}
LinearLayout layout1 = (LinearLayout) picker.getChildAt(0);
if (picker instanceof TimePicker) {
if (layout1.getChildAt(1) instanceof NumberPicker) {
NumberPicker v1 = (NumberPicker) layout1.getChildAt(1);
final int count = v1.getChildCount();
for (int i = 0; i < count; i++) {
View child = v1.getChildAt(i);
try {
Field wheelpaint_field = v1.getClass().getDeclaredField("mSelectorWheelPaint");
wheelpaint_field.setAccessible(true);
((Paint) wheelpaint_field.get(v1)).setTypeface(//your font here);
((Paint) wheelpaint_field.get(v1)).setColor(getResources().getColor(R.color.colorOrange));
((EditText) child).setTypeface(// your font here);
v1.invalidate();
} catch (Exception e) {
//TODO catch.
//If java cant find field then it will catch here and app wont crash.
}
}
}
}
LinearLayout layout = (LinearLayout) layout1.getChildAt(0);
for (int j = 0; j < 3; j++) {
try {
if (layout.getChildAt(j) instanceof NumberPicker) {
NumberPicker v1 = (NumberPicker) layout.getChildAt(j);
final int count = v1.getChildCount();
for (int i = 0; i < count; i++) {
View child = v1.getChildAt(i);
try {
Field wheelpaint_field = v1.getClass().getDeclaredField("mSelectorWheelPaint");
wheelpaint_field.setAccessible(true);
((Paint) wheelpaint_field.get(v1)).setTypeface(//your font here);
((Paint) wheelpaint_field.get(v1)).setColor(getResources().getColor(R.color.colorOrange));
((EditText) child).setTypeface(//your font here);
v1.invalidate();
} catch (Exception e) {
//TODO catch.
//If java cant find field then it will catch here and app wont crash.
}
}
}
} catch (Exception e) {
//TODO catch.
//If java cant find field then it will catch here and app wont crash.
}
}
}
If you can use DatePickerDialog, then u can simply get the buttons of the dialog, like:
DatePickerDialog datePickerDialog; // GET your dialog
datePickerDialog.show();
datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).setTextSize(30); // 30 is your text size
datePickerDialog.getButton(DatePickerDialog.BUTTON_NEGATIVE).setTextSize(30);
Kotlin-Anko equivalent to SKG's solution
startTimePicker = timePicker {
this.applyRecursively {
when(it) {
is NumberPicker -> {
val paintField = it.javaClass.getDeclaredField("mSelectorWheelPaint")
paintField.isAccessible = true
(paintField.get(it) as? Paint)?.typeface = //your font here
}
is TextView -> {
it.typeface = //your font here
}
}
}

Categories

Resources