(Animation) Hide Toolbar in Fragment - android-layout

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?

Related

using shared peferences to save colors

I have an app that uses a color picking dialog to change the app background color, and the text color. The color picker works fine, but when the app closes for any reason it reverts back to default.
I have checked: http://developer.android.com/guide/topics/data/data-storage.html#pref
and
Android Shared preferences example
the below code is the result of my research. The problem I'm having is all my text fields start off without text color, when i use the color dialog the colors change just fine, but are not saved.
Any pointers on where I'm going wrong would be greatly appreciated.
public class TipCalculator extends ActionBarActivity implements ColorPickerDialog.OnColorChangedListener {
//UI element objects to be manipulated.
TextView tipper;
TextView diner;
/*few TextView items left out to save space*/
int color;
RelativeLayout RLayout;
private SharedPreferences preferences;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tip_calculator);
preferences = getSharedPreferences("TipCalculator", MODE_PRIVATE);
//color = preferences.getInt("TipCalculator", color); did not change anything
color = preferences.getInt("bg_color", color);
RLayout = (RelativeLayout) findViewById(R.id.RLayout);//layout object for background color manipulation
bill = (EditText) findViewById(R.id.bill_amount_text);//UI elements placed in objects for text color manipulation
billNtip = (TextView) findViewById(R.id.bill_tip_text);
/*few TextView items left out to save space*/
bill.setSelection(bill.getText().length());
bill.addTextChangedListener(billWatcher);
}
#Override
public void onPause(){// onStop does not seem to change how the app currently runs
super.onPause();
/*preferences = getSharedPreferences("TipCalculator", MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit(); does not work*/
SharedPreferences.Editor editor = getSharedPreferences("TipCalculator", MODE_PRIVATE).edit();
//editor.putInt("TipCalculator", color); does not change anything
editor.putInt("bg_color", color);
editor.commit();
tipper.setTextColor(color);
bill.setTextColor(color);
/*few TextView items left out to save space*/
}
#Override
public void colorChanged(String key, int color) {
color = newColor;
if (decide.equals("font"))
{
tipper.setTextColor(color);
bill.setTextColor(color);
/*few TextView items left out to save space*/
}
else if (decide.equals("background"))
{
RLayout.setBackgroundColor(color);
}
}
Save the color to the SharedPreferences in onPause() instead of onResume(), like this:
#Override
public void onPause() {
SharedPreferences.Editor editor = getSharedPreferences("TipCalculator", MODE_PRIVATE).edit();
editor.putInt("bg_color", color);
editor.commit();
super.onPause();
}
onResume() is called when your app resumes, so if you exit but don't resume, the value won't get saved.
Somewhere in your initialization you will also need to read the color value out of the SharedPreferences e.g:
preferences = getSharedPreferences("TipCalculator", MODE_PRIVATE);
color = preferences.getInt("bg_color", android.R.color.white); // default to white or whatever color you want
tipper.setTextColor(color);
bill.setTextColor(color);
It doesn't look like you are setting the color on the tipper and bill
objects after you load it. In onCreate() after you call getInt() add
these lines: tipper.setTextColor(color); bill.setTextColor(color); You
will need to initialize these objects first obviously. – samgak
This was the final thing I was missing.
Thanks again for the help.

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

ListView clipping

i working little bit with the ListView from JavaFx2. I´m running into one issue.
Is it possible to turn off the clipping of the ListCell/ListView?
I add an ImageView that has to be wider than the ListView and JavaFx2 shows automatically a scrollbar.
This my code snipped how i add the ImageView to my List:
list.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
#Override
public ListCell<String> call(ListView<String> param) {
final ListCell<String> blub = new ListCell<String>() {
#Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
StackPane p = new StackPane();
Label label = new Label(item);
p.getChildren().addAll(img, label);
setGraphic(p);
p.setAlignment(Pos.CENTER_LEFT);
}
}
};
blub.setStyle("-fx-background-color:transparent");
return blub;
}
});
Big thanks!
I don't think it's possible.
Maybe try to play with the Skin of the ListView. It seems that the scroll bar are managed in this class. It do not use a scroll pane.
Another solution could be replacing the ListView by a VBox in a ScrollPane.
Finally, you could try to modify img (by the way, where it come from, and what Class is it ?) to only show what you need.
Anyway, I'm interested by the solution you will use.

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

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

Resources