Is there a default Android view widget with textbox and 2 knobs? - android-layout

Is there a default view that allows a number textbox, which can be changed by typing in the textbox or by two adjacent knobs by the textbox. So basically, in awesome ASCII graphics:
[<] [textbox] [>]
Basically an increment button, textbox, and decrement button.

Since API level 11, you can now use the NumberPicker;
You can find the documentation here
You can find an example here

My custom solution using EditText and two Button objects:
// This is a textbox group with two knob buttons
LinearLayout boxGroup = new LinearLayout(this);
boxGroup.setOrientation(LinearLayout.HORIZONTAL);
//Stores the current value in the textbox
final int[] value = {0};
// Editable text box
final EditText editText = new EditText(this);
editText.setText("" + value[0]);
// Decrement button
Button decrementButton = new Button(this);
decrementButton.setText("<");
decrementButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
value[0]++;
editText.setText("" + value[0]);
}
});
// Increment button
Button incrementButton = new Button(this);
incrementButton.setText(">");
incrementButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
value[0]--;
editText.setText("" + value[0]);
}
});
boxGroup.addView(decrementButton);
boxGroup.addView(editText);
boxGroup.addView(incrementButton);

Related

How to change the font size of content when radio button clicks?

I have a WebView and I am loading the data from the backend.The data is very long paragraph and it is in Html format.It is working.I have to implement change font size settings to my application.When radio button named "small" clicks,text should appear in small font,when "large" clicks text should appear in large font.The content dispaly is done in ChapterDetailFragment.class.The dialg which shows the "change font option" is in Menu in actionbar and in drawer.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.font_change) {
dialog = new Dialog(HomeActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.font_change_dialog);
dialog.show();
dialog.setCanceledOnTouchOutside(true);
//here i have to write the code for clicks of radiobutton "small","large"
}
}
This is the line for loading paragraph to the array adapter
ParagraphAdapter.class
mViewHolder.mChapterContextTextView.loadData(getItem(position - 1).getContent(), "text/html; charset=UTF-8;", null);
I don't know how to implement this.Please anyone help me
in onClick of "large" radio button, save value LARGE for large.Similarly in onClick of small radio button(value SMALL for small )
public void onTextLarge(View view) {
if (fragment.getClass().getSimpleName().equalsIgnoreCase("HomeFragment")){
setSharedPreference("FONT","LARGE");
fragment = new HomeFragment();
dialog.dismiss();
}
In the adapter,
if (fontsize.equals("LARGE")) {
mViewHolder.settings = mViewHolder.mChapterContextTextView.getSettings();
mViewHolder.settings.setTextZoom(mViewHolder.settings.getTextZoom() + 30);
mViewHolder.mChapterContextTextView.loadData(getItem(position - 1).getContent(),
"text/html; charset=UTF-8;", null);
Similarly done for fontsize.equals("SMALL"). :)

(Animation) Hide Toolbar in Fragment

Hey i want to hide my toolbar when i click inside an editText Therefore i added these lines
mORMetWeight.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!enterWeightClicked) {
enterWeightClicked = true;
Toolbar mToolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
mToolbar.setVisibility(View.GONE);
mContainer.removeView(cv1);
mContainer.removeView(cv2);
mContainer.getChildAt(0);
header.getLayoutParams().height = (int) getResources().getDimension(R.dimen.smallEnterWeightHeight);
In my onCreateView method i added the transition effect but the animation now of the Toolbar looks horrible..
LayoutTransition transition = mContainer.getLayoutTransition();
transition.enableTransitionType(LayoutTransition.CHANGING);
I simply like to let the Toolbar scroll out and the view to the top? Is this possible with the "simple" animation style?

changing text of edit box in list view on button click in android

I am using a ListView, in which i have inflated another layout template which contains 2 Images, an edit text, a correction button , and 2 more buttons, one of which is quick edit button and now I want on click on this quick edit button the edit text should become editable and the correction button should become visible. can u please help me.
From the comments, for easy reading:
mv.quick_edit = (ImageButton)convertView.findViewById
(R.id.gateway_list_info_image_button_temp);
mv.quick_edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
MyViewHolder m = new MyViewHolder();
m.correct_button.setVisibility(View.VISIBLE);
m.edit_text.setText("text changed");
}
});
in the adapter's getView method, i believe you have:
editText = (EditText)mView.findViewById(id here);
btnEdit= (Button)mView.findViewById(id here);
set the onClickListener() of the button in the getView method, and inside the onclick, set visibility to invisible or gone, for the other button you mentioned, and set the setEnabled method to true for the editText.
I hope this much clue helps.
EDIT:
For using a viewHolder in your code, please refer to this
Code Snippets:
if(convertView==null){
// inflate the layout
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
convertView = inflater.inflate(layoutResourceId, parent, false);
// well set up the ViewHolder
viewHolder = new ViewHolderItem();
viewHolder.textViewItem = (TextView) convertView.findViewById(R.id.textViewItem);
// store the holder with the view.
convertView.setTag(viewHolder);
}else{
// we've just avoided calling findViewById() on resource everytime
// just use the viewHolder
viewHolder = (ViewHolderItem) convertView.getTag();
}
It is after the else block that you define the onClickListeners and use viewHolder.editText.setVisibility(View.INVISIBLE)

can i put a dialog in a spinner item?

I'm new in the android world but I got experience in java.
Im trying to show a dialog when I select an especific item in my spinner but, when I do it, my application has stopped.
I have 1 fragment and 1 class for the listener, instantiate an object from the fragment in the listener and try to call the dialog.
The code is somthing like this:
//Instantiate of class Guardar extends SherlockFragment.
Guardar controlador = new Guardar();
public void onItemSelected(final AdapterView parent, View view, int pos,long id) {
String addSM = parent.getItemAtPosition(pos).toString();
if (addSM == “Anyadir”){
// custom dialog
final Dialog dialog = new Dialog(controlador.context);
dialog.setContentView(R.layout.dialog_afegirsuper);
dialog.setTitle(“Title…”);
// set the custom dialog components – text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText(“Android custom dialog example!”);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
Is this possible to implement? another similar idea?
thanks a lot for any solution

how to align the table layout in android

i am developing some web service based android application ...i want to show below type table view in my application..how can i do?
dynamic table layout code
for (int i = 0; i < 1; i++) {
final LinearLayout linear = new LinearLayout(
FifthActivity.this);
MainLayout.setWeightSum(1.0f);
TableRow row1 = new TableRow(FifthActivity.this);
row1.setId(1000 + sCount);
TextView text1 = new TextView(FifthActivity.this);
text1.setText(button.getText());
final Button button = new Button(FifthActivity.this);
EditText e = new EditText(FifthActivity.this);
e.setWidth(20);
e.setHeight(20);
button.setText(" X ");
button.setWidth(20);
button.setHeight(20);
button.setId(2000 + sCount);
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
MainLayout.removeView(findViewById(v
.getId() - 1000));
}
});
sCount++;
row1.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, 0, 0.25f));
row1.addView(text1);
row1.addView(e);
row1.addView(button);
MainLayout.addView(row1);
}
ll.addView(MainLayout);
// TODO Auto-generated method stub
here's output
how can i align this table column as view format....pls any one help me....
thank in advance.....
You shouldn't need to call setWeightSum() on your parents.
What is the type of your MainLayout ?
I guess its not a TableLayout since table rows in TableLayout get aligned automatically.
So making your MainLayout a TableLayout should do what you want.
see the TableLayout documentation here.

Resources