I'm trying to generate form elements from a template when the user clicks on a button. I created the template and the container layout for the new forms with XML. Its successfully generating the first form where I'm telling it to generate, but when I try to generate more forms beyond the first one its giving me an error: "the specified child already has a parent. You must call removeView() on the child's first parent". Any clue as to what I should do so as to generate more than one element? I've tried changing the id of the newly created forms but that's giving me a null pointer exception and crashing. Thank you.
public class MakeQuestion extends Activity implements OnClickListener{
private static final int MY_BUTTON = 9000;
int templateID = 1;
Button b;
Button target;
View insertPoint;
Button testTemplate;
View v1;
RelativeLayout.LayoutParams templateParams;
LayoutInflater vi;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.make_question);
Initialize();
}
public void Initialize(){
//button for adding new forms
b = (Button) findViewById(R.id.makeLayoutButton);
b.setOnClickListener(this);
//get the template form to be duplicated
vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v1 = vi.inflate(R.layout.form_template, null);
//set the params for the element that will have dynamically generated content below it
templateParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//container where forms will be contained in
insertPoint = findViewById(R.id.questionsContainer);
//view where new form will go below
View belowContainer = findViewById(R.id.questionTemplateFake);
//set id for layout params of view
belowContainer.setId(1);
//set rule for new forms to go below view 'belowContainer'
templateParams.addRule(RelativeLayout.BELOW, belowContainer.getId());
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.makeLayoutButton:
v1 = vi.inflate(R.layout.form_template, null);
//add view to the insertPoint
((LinearLayout) insertPoint).addView(v1);
break;
}
}
}
Added forms should go in "questionsContainer" which is set to be below "questionTemplateFake"
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/grey_background" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#8B459A"
android:baselineAligned="false"
android:clipToPadding="false" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/logo_small" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:src="#drawable/settings" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:src="#drawable/search" />
</RelativeLayout>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/relativeLayout1" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relative12"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="WHAT IS YOUR QUESTION?" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/save_button"
android:layout_alignBottom="#+id/save_button"
android:layout_alignRight="#+id/textView1"
android:text="ADD PICTURE OR VIDEO"
android:textSize="10sp" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="14dp"
android:background="#drawable/textlines"
android:ems="10"
android:hint="50 WORDS OR LESS"
android:inputType="textMultiLine"
android:paddingLeft="5dp" />
<Button
android:id="#+id/save_button"
android:layout_width="75dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_below="#+id/editText1"
android:layout_marginTop="16dp"
android:background="#drawable/purplebutton"
android:text="BROWSE"
android:textColor="#drawable/button_text_color"
android:textSize="10sp" />
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/save_button"
android:layout_marginTop="25dp"
android:text="CREATE AN ANSWER" />
<RelativeLayout
android:id="#+id/questionTemplateFake"
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/TextView01" >
<Button
android:id="#+id/Button02eew"
android:layout_width="75dp"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/purplebutton"
android:text="BROWSE"
android:textColor="#drawable/button_text_color"
android:textSize="10sp" />
<EditText
android:id="#+id/EditText02"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_above="#+id/Button02"
android:layout_alignParentLeft="true"
android:background="#drawable/textlines"
android:ems="10"
android:hint="50 WORDS OR LESS"
android:inputType="textMultiLine"
android:paddingLeft="5dp" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/TextView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginRight="19dp"
android:layout_toLeftOf="#+id/Button02"
android:text="ADD PICTURE OR VIDEO"
android:textSize="10sp" />
</RelativeLayout>
<LinearLayout
android:id="#+id/questionsContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="20dp"
android:orientation="vertical"
android:layout_below="#+id/questionTemplateFake"
>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/makeLayoutButton"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_below="#+id/scrollView1"
android:layout_marginRight="17dp"
android:layout_marginTop="79dp"
android:background="#drawable/purplebutton"
android:text="MORE OPTIONS"
android:textColor="#drawable/button_text_color"
android:textSize="10sp" />
</RelativeLayout>
You are trying to add the same instance over and over again. Thus the message that "specific child already exists". You would have to create a new template layout instance with different ID (I suppose) and then try to add it in.
So rather than:
((RelativeLayout) insertPoint).addView(v1, templateParams);
and adding v1 again. Create a new instance
v1 = vi.inflate(R.layout.form_template, null);
set the id for good measures and then add it again in view.
I suppose you don't need to set the id, but you can read more about how id's work here
Related
Why do I always see the last id no matter which text I click?
I would like to see the right fragment displayed in the layout that i created according to the relevant text clicked. I always see the 'alternatives' fragment.
I understood that tags could be helped, but I could not figure out how to use them.
In addition, I tried to use diffrent versions of FragmentManager and FragmentTransaction and even to remove the switch and call each setOnClickListener of textview separately but nothing helped.
This is my Activity file:
IngredientsFragment ingredientsFragment;
FavouritesFragment favouritesFragment;
FeedbacksFragment feedbacksFragment;
Write_Feedback_Fragment writeFeedbackFragment;
AlternativesFragment alternativesFragment;
TextView ingredients;
TextView favourites;
TextView feedbacks;
TextView alternatives;
TextView writeFeedback;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_product_details);
window=this.getWindow();
window.setStatusBarColor(this.getResources().getColor(R.color.colorPrimaryDark));
ingredients= (TextView) findViewById(R.id.ingredients_option);
favourites= (TextView) findViewById(R.id.favorites_option);
feedbacks= (TextView) findViewById(R.id.watch_feedback_option);
writeFeedback= (TextView) findViewById(R.id.add_feedback_option);
alternatives= (TextView) findViewById(R.id.alternatives_option);
ingredients.setOnClickListener(this);
favourites.setOnClickListener(this);
feedbacks.setOnClickListener(this);
writeFeedback.setOnClickListener(this);
alternatives.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId())
{
case R.id.ingredients_option:
ingredientsFragment= new IngredientsFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,ingredientsFragment).commit();
break;
case R.id.favorites_option:
favouritesFragment= new FavouritesFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,favouritesFragment).commit();
break;
case R.id.watch_feedback_option:
feedbacksFragment= new FeedbacksFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,feedbacksFragment).commit();
break;
case R.id.add_feedback_option:
writeFeedbackFragment= new Write_Feedback_Fragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,writeFeedbackFragment).commit();
break;
case R.id.alternatives_option:
alternativesFragment= new AlternativesFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,alternativesFragment).commit();
break;
}
}
}
This is my XML file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ProductDetails">
<RelativeLayout
android:id="#+id/recommendation_template"
android:layout_width="match_parent"
android:layout_height="142dp"
android:background="#android:color/white">
<ImageView
android:id="#+id/registartion_arrow"
android:layout_width="45dp"
android:layout_height="34dp"
android:layout_alignParentRight="true"
android:src="#drawable/ic_arrow_forward_black_24dp" />
<TextView
android:id="#+id/rec_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="10dp"
android:text="Recommendation:"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="#android:color/black"/>
<ImageView
android:id="#+id/vi_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rec_tv"
android:layout_alignParentLeft="true"
android:layout_marginLeft="0dp"
android:layout_marginTop="26dp"
android:paddingLeft="80dp"
android:src="#drawable/ic_check" />
<TextView
android:id="#+id/vi_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/vi_image"
android:layout_marginLeft="4dp"
android:layout_marginTop="-29dp"
android:layout_toRightOf="#id/vi_image"
android:text="This is for you"
android:textColor="#android:color/black"
android:textSize="20dp" />
<ImageView
android:id="#+id/not_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/vi_image"
android:layout_alignParentLeft="true"
android:layout_marginLeft="0dp"
android:layout_marginTop="3dp"
android:paddingLeft="80dp"
android:src="#drawable/ic_do_not" />
<TextView
android:id="#+id/not_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/not_image"
android:layout_marginLeft="5dp"
android:layout_marginTop="-27dp"
android:layout_toRightOf="#id/not_image"
android:text="Not for you"
android:textColor="#android:color/black"
android:textSize="20dp" />
</RelativeLayout>
<HorizontalScrollView
android:id="#+id/recommendation_scrollView"
android:layout_width="match_parent"
android:layout_height="83dp"
android:layout_below="#id/recommendation_template"
android:layout_marginTop="7dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/recommendation_template"
style="?android:attr/borderlessButtonStyle">
<TextView
android:id="#+id/ingredients_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:drawableTop="#drawable/ingredients"
android:text="Ingredients" />
<TextView
android:id="#+id/favorites_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:drawableTop="#drawable/ic_star"
android:paddingLeft="80dp"
android:text="Favorites" />
<TextView
android:id="#+id/watch_feedback_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:drawableTop="#drawable/customer_review"
android:paddingLeft="145dp"
android:text="Feedbacks" />
<TextView
android:id="#+id/add_feedback_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:drawableTop="#drawable/write_feedback"
android:paddingLeft="220dp"
android:text="Write feedback" />
<TextView
android:id="#+id/alternatives_option"
android:layout_width="408dp"
android:layout_height="90dp"
android:layout_gravity="left"
android:drawableTop="#drawable/ic_alternatives"
android:paddingLeft="320dp"
android:text="Alternatives" />
</FrameLayout>
</HorizontalScrollView>
<ScrollView
android:id="#+id/scrollView_container"
android:layout_width="match_parent"
android:layout_height="499dp"
android:layout_below="#id/recommendation_scrollView">
<RelativeLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="463dp">
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Your code should work like that. The problem is your layout. See the textviews in your FrameLayout. Your defining a paddingLeft and layout_width so, that your textview alternatives_option is overlaying all the other textviews. Thats why in the onclick you always get the id of that view.
I suggest doing a tutorial about XML layout.
<TextView
android:id="#+id/alternatives_option"
android:layout_width="408dp"
android:layout_height="90dp"
android:layout_gravity="left"
android:drawableTop="#drawable/ic_alternatives"
android:paddingLeft="320dp"
android:text="Alternatives" />
I want to add functionality like snapchat's "add caption" in my recent project.
Expected Output: when I click on add text button, one caption bar appears with EditText and open keyboard user can feed text. If I click on layout keyboard, it closes automatically and it looks like a TextView and caption bar can move through screen at y axis.
Tried and failed: when I click on add text button, one caption bar appears with EditText, caption bar can't move through screen at y axis (if I take the TextView it works fine but not with EditText). Because I can't click on layout.
I also tried property like clickable false. But it's not working
My Question: How to show EditText as TextView while there's only touch event, while click on it works as EditText?
I fail to take click and touch on layout after adding edittext text value.
here's my code:
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rel_Main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black"
android:clickable="true">
<FrameLayout
android:id="#+id/frame_cameraHolder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/iv_cameraMain"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<RelativeLayout
android:id="#+id/rel_cameraTitleHolder1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp">
<ImageButton
android:id="#+id/ib_cameraClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#android:color/transparent"
android:src="#drawable/ic_close_white" />
<ImageButton
android:id="#+id/ib_cameraForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="24dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_forward" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_cameraTitleHolder2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:visibility="gone">
<ImageButton
android:id="#+id/ib_cameraCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#android:color/transparent"
android:src="#drawable/ic_close_white" />
<ImageButton
android:id="#+id/ib_cameraBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#android:color/transparent"
android:src="#drawable/ic_back" />
<ImageButton
android:id="#+id/ib_cameraStickers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_toLeftOf="#+id/ib_cameraDraw"
android:background="#android:color/transparent"
android:src="#drawable/ic_sticker" />
<ImageButton
android:id="#+id/ib_cameraDraw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_toLeftOf="#+id/ib_cameraText"
android:background="#android:color/transparent"
android:src="#drawable/ic_draw" />
<ImageButton
android:id="#+id/ib_cameraText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="24dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_text" />
</RelativeLayout>
<!--<uz.shift.colorpicker.LineColorPicker
android:id="#+id/color_picker"
android:layout_width="match_parent"
android:layout_height="60dp"
app:orientation="horizontal"
android:visibility="gone"/>-->
<RelativeLayout
android:id="#+id/rel_cameraTextHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp"
android:visibility="gone">
<ImageButton
android:id="#+id/ib_cameraTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#android:color/transparent"
android:src="#drawable/ic_fontstyle" />
<TextView
android:id="#+id/ib_cameraDone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="24dp"
android:text="Done"
android:textColor="#color/white"
android:textSize="20dp"
android:textStyle="bold" />
</RelativeLayout>
<!--diff-->
<RelativeLayout
android:id="#+id/rel_cameraHolder1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="visible">
<ImageButton
android:id="#+id/ib_cameraflash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="50dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_flash" />
<Button
android:id="#+id/btn_cameraCapturePic"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_centerHorizontal="true"
android:background="#drawable/btn_capture" />
<ImageButton
android:id="#+id/ib_cameraReverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="50dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_reverse" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_cameraHolder2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone">
<FrameLayout
android:id="#+id/frame_cameraTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp">
<ImageButton
android:id="#+id/ib_cameraTimer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="24dp"
android:background="#android:color/transparent"
android:src="#drawable/ic_blanck_timer" />
<TextView
android:id="#+id/text_cameraTimerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="34dp"
android:layout_marginTop="6dp"
android:text="1"
android:textColor="#color/white"
android:textSize="8dp"
android:textStyle="bold" />
</FrameLayout>
<ImageButton
android:id="#+id/ib_cameraSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_toRightOf="#+id/frame_cameraTimer"
android:background="#android:color/transparent"
android:src="#drawable/ic_save" />
<ImageButton
android:id="#+id/ib_cameraYourStory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_toRightOf="#+id/ib_cameraSave"
android:background="#android:color/transparent"
android:src="#drawable/ic_add" />
<ImageButton
android:id="#+id/ib_cameraSaveForward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="24dp"
android:background="#drawable/btn_capture"
android:src="#drawable/ic_forward" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_cameraDeleteHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone">
<ImageButton
android:id="#+id/ib_cameraDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#android:color/transparent"
android:src="#drawable/ic_delete" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rel_EdtAddedText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:orientation="horizontal"/>
</RelativeLayout>
MainActivity.java
private void setAddedEditTextDynamically() {
mRelativeLayoutHolder2.setVisibility(View.GONE);
//create dynamic edit text
RelativeLayout.LayoutParams lparams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
final EditText edtAddedText = new EditText(MainActivity.this);
lparams.addRule(RelativeLayout.CENTER_IN_PARENT);
edtAddedText.setLayoutParams(lparams);
edtAddedText.setTextColor(getResources().getColor(R.color.white));
edtAddedText.setGravity(Gravity.CENTER_HORIZONTAL);
// add edittext to rel layout
mRelEdtAddedText.addView(edtAddedText);
mRelEdtAddedText.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
mRelEdtAddedText.setOnTouchListener(new View.OnTouchListener() {
PointF DownPT = new PointF(); // Record Mouse Position When Pressed Down
PointF StartPT = new PointF(); // Record Start Position of 'img'
#Override
public boolean onTouch(View v, MotionEvent event) {
int eid = event.getAction();
switch (eid) {
case MotionEvent.ACTION_MOVE:
PointF mv = new PointF(event.getX() - DownPT.x, event.getY() - DownPT.y);
// mLinMain.setX((int)(StartPT.x+mv.x));
mRelEdtAddedText.setX(10);
mRelEdtAddedText.setY((int) (StartPT.y + mv.y));
StartPT = new PointF(mRelEdtAddedText.getX(), mRelEdtAddedText.getY());
break;
case MotionEvent.ACTION_DOWN:
DownPT.x = event.getX();
DownPT.y = event.getY();
StartPT = new PointF(mRelEdtAddedText.getX(), mRelEdtAddedText.getY());
break;
case MotionEvent.ACTION_UP:
break;
default:
break;
}
return true;
}
});
}
This is what happen when i set a 'view' for my empty view. (the empty view fit inside the whole screen instead listview's size.
issue
i want to fit my empty view inside the blue area (see the image) :
enter image description here
empty_items
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bdbdbd">
<ImageView
android:id="#+id/image1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:background="#mipmap/ic_inf"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:contentDescription="information">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="168dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="SIN NADA POR MOSTRAR"
android:textAlignment="center"
android:textSize="32sp"
android:textStyle="bold"
android:textColor="#757575"
android:id="#+id/infoMsgTextView"
android:layout_gravity="center_horizontal|bottom"
android:layout_alignParentTop="false"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="true"
android:layout_marginTop="224dp"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true"/>
sales_fragment.xml - a fragment with the listview that i want to set empty view.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fbutton="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:htext="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:fab="http://schemas.android.com/apk/res-auto"
tools:context=".controler.SalesFragment"
android:visibility="visible"
>
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="165dp"
android:layout_gravity="center"
android:background="#144257"
android:id="#+id/relativeLayout"
android:layout_below="#+id/tvClient"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:background="#drawable/roundedshadow_et"
android:ems="10"
android:id="#+id/discountEditText"
android:elegantTextHeight="false"
android:hint="#string/discountHint"
android:textColorHint="#FFFF"
android:textColor="#FFFF"
android:textAlignment="center"
android:layout_alignTop="#+id/etPrice"
android:layout_toLeftOf="#+id/etPrice"
android:layout_toStartOf="#+id/etPrice"/>
<AutoCompleteTextView
android:layout_width="300dp"
android:background="#drawable/roundedshadow_et"
android:layout_height="60dp"
android:singleLine="true"
android:scrollHorizontally="true"
android:id="#+id/productAutoCompleteTextView"
android:hint="#string/product"
android:textColorHint="#FFFF"
android:layout_gravity="center"
android:textAlignment="center"
android:textColor="#ffff"
android:visibility="visible"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:background="#drawable/roundedshadow_et"
android:ems="10"
android:id="#+id/amountEditText"
android:elegantTextHeight="false"
android:textAlignment="center"
android:textColor="#FFFF"
android:textColorHint="#FFFF"
android:hint="#string/amountHint"
android:layout_alignTop="#+id/discountEditText"
android:layout_alignLeft="#+id/productAutoCompleteTextView"
android:layout_alignStart="#+id/productAutoCompleteTextView"/>
<info.hoang8f.widget.FButton
android:layout_width="70dp"
android:layout_height="wrap_content"
fbutton:buttonColor="#144257"
fbutton:shadowColor="#0e2e3c"
fbutton:shadowEnabled="true"
fbutton:shadowHeight="5dp"
fbutton:cornerRadius="5dp"
android:textColor="#ffff"
android:textAlignment="center"
android:text="#string/addProduct"
android:id="#+id/addProductBtn"
android:layout_below="#+id/discountEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"/>
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:background="#drawable/roundedshadow_et"
android:ems="10"
android:id="#+id/etPrice"
android:elegantTextHeight="false"
android:textAlignment="center"
android:textColor="#FFFF"
android:textColorHint="#FFFF"
android:hint="#string/priceHint"
android:layout_centerVertical="true"
android:layout_alignRight="#+id/productAutoCompleteTextView"
android:layout_alignEnd="#+id/productAutoCompleteTextView"/>
</RelativeLayout>
<com.hanks.htextview.HTextView
android:id="#+id/tvClient"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="#144257"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="15sp"
htext:animateType="anvil"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAlignment="center"/>
<com.hanks.htextview.HTextView
android:id="#+id/tvPrice"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="#144257"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="15sp"
htext:animateType="anvil"
android:textAlignment="center"
android:layout_below="#+id/relativeLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/sale_floating_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:menu_animationDelayPerItem="55"
fab:menu_backgroundColor="#color/fbutton_color_transparent"
fab:menu_buttonSpacing="0dp"
fab:menu_colorNormal="#e040fb"
fab:menu_colorPressed="#4d0359"
fab:menu_colorRipple="#99d4d4d4"
fab:menu_fab_label="Opciones de venta"
fab:menu_fab_size="normal"
fab:menu_icon="#mipmap/shopping_cart"
fab:menu_labels_colorNormal="#333"
fab:menu_labels_colorPressed="#444"
fab:menu_labels_colorRipple="#66efecec"
fab:menu_labels_cornerRadius="3dp"
fab:menu_labels_ellipsize="none"
fab:menu_labels_hideAnimation="#anim/fab_slide_out_to_right"
fab:menu_labels_margin="0dp"
fab:menu_labels_maxLines="-1"
fab:menu_labels_padding="8dp"
fab:menu_labels_position="left"
fab:menu_labels_showAnimation="#anim/fab_slide_in_from_right"
fab:menu_labels_showShadow="true"
fab:menu_labels_singleLine="false"
fab:menu_labels_textColor="#f2f1f1"
fab:menu_labels_textSize="15sp"
fab:menu_openDirection="up"
fab:menu_shadowColor="#66aff198"
fab:menu_shadowRadius="4dp"
fab:menu_shadowXOffset="1dp"
fab:menu_shadowYOffset="4dp"
fab:menu_showShadow="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
>
<com.github.clans.fab.FloatingActionButton
android:id="#+id/floating_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/add_tag"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/floating_checkout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/checkout"
fab:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvPrice">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:longClickable="true"
android:id="#+id/lvCart"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
SalesFragment.java
#Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container,
Bundle savedInstanceState)
{
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_sales, container, false);
neverEmptyListView = (ListView) view.findViewById(R.id.lvCart);
ViewGroup headerView = (ViewGroup) getActivity().getLayoutInflater().inflate(R.layout.header_row_layout, neverEmptyListView, false);
neverEmptyListView.addHeaderView(headerView);
View emptyView = getActivity().getLayoutInflater().inflate(R.layout.empty_items, null);
emptyMsg = (TextView) emptyView.findViewById(R.id.infoMsgTextView);
emptyMsg.setText("Agregue productos para la venta");
getActivity().addContentView(emptyView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
neverEmptyListView.setEmptyView(emptyView);
items = new ArrayList<String>();
lvAdapter = new ListViewAdapter
(getContext(), R.layout.row_layout, R.id.description, items);
neverEmptyListView.setAdapter(lvAdapter);
i solve my problem this way:
((ViewGroup)neverEmptyListView.getParent()).addView(emptyView);
neverEmptyListView.setEmptyView(emptyView);
I nedd to click on items in list activity to do something, but its not working
i search for this problem and saw some answers about this such as :
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
or
android:descendantFocusability="afterDescendants"
android:descendantFocusability="beforeDescendants"
android:descendantFocusability="blocksDescendants"
but those are not worked
this is my listActivity :
public class TrainListActivity extends SherlockListActivity
{
public static String varStart = "com.example.traininfo.startcity";
public static String varDestination = "com.example.traininfo.destinationcity";
private String start;
private String destination;
ArrayList<TrainType> trains;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_trainlist);
Log.i("SearchTrain", "try to get extras...");
start = getIntent().getExtras().getString(varStart);
destination = getIntent().getExtras().getString(varDestination);
TrainController tc = new TrainController(this);
trains = new ArrayList<TrainType>();
trains = tc.getTrainList(start, destination).getTrain();
Log.i("SearchTrain", "got the train list...");
TrainListAdapter adapter = new TrainListAdapter(this, trains);
Log.i("SearchTrain", "adapter initialized successfully!!");
setListAdapter(adapter);
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
// I want to do something here :(
super.onListItemClick(l, v, position, id);
Log.i("trainList", "on click");
}
}
row xml file :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#27ae60"
android:paddingBottom="5dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true" >
<TextView
android:id="#+id/tvTrainName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="#string/resultTrainName"
android:textColor="#android:color/white"
android:textSize="20sp"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:textStyle="bold" />
<TextView
android:id="#+id/tvStartLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/tvTrainName"
android:gravity="right"
android:text="#string/resultTimeOut"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvTimeOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tvTrainName"
android:layout_marginRight="30sp"
android:layout_toLeftOf="#id/tvStartLabel"
android:text="#string/resultTimeOutEx"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvFinishLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/tvStartLabel"
android:gravity="right"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:text="#string/resultTimeIn"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvTimeIn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvTimeOut"
android:layout_below="#id/tvTimeOut"
android:text="#string/resultTimeInEx"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvPrices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/tvTimeIn"
android:gravity="right"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
android:textColor="#android:color/white"
android:textSize="15sp" />
<ImageButton
android:id="#+id/btnMoreInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="23dp"
android:focusable="false"
android:clickable="false"
android:focusableInTouchMode="false"
android:background="#android:color/transparent"
android:contentDescription="#string/resultMoreInfo"
android:src="#drawable/action_info" />
and ListActivity xml File :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:clickable="true"
android:descendantFocusability="afterDescendants" />
</LinearLayout>
please help me :(
Use normal activity and put a ListView in xml. Use inflator to use your custom row design. Just put the focusable=false for your imagebutton. It will allow you to click on the row and you can apply a separate click listener for your imagebutton to handle its click separately.
I faced the same problem not too long ago. It seems that the ImageButton takes focus regardless what you do. What I did was to replace the ImageButton with and ImageView and set the listener to it.
This is how your xml files should look like.
row xml file :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#27ae60"
android:paddingBottom="5dp" >
<TextView
android:id="#+id/tvTrainName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="#string/resultTrainName"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvStartLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/tvTrainName"
android:gravity="right"
android:text="#string/resultTimeOut"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvTimeOut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tvTrainName"
android:layout_marginRight="30sp"
android:layout_toLeftOf="#id/tvStartLabel"
android:text="#string/resultTimeOutEx"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvFinishLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/tvStartLabel"
android:gravity="right"
android:text="#string/resultTimeIn"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvTimeIn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvTimeOut"
android:layout_below="#id/tvTimeOut"
android:text="#string/resultTimeInEx"
android:textColor="#android:color/white"
android:textSize="15sp" />
<TextView
android:id="#+id/tvPrices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/tvTimeIn"
android:gravity="right"
android:textColor="#android:color/white"
android:textSize="15sp" />
<ImageView
android:id="#+id/btnMoreInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="23dp"
android:background="#android:color/transparent"
android:contentDescription="#string/resultMoreInfo"
android:src="#drawable/action_info" />
Activity xml.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
</LinearLayout>
Hi i'm using eclipse for deveoping this android app. I'm inflating a layout using inflator and everything works fine.. I'm adding those inflated items one by one to another layout, so when the device's orientation is changed, all those inflated items are gone. The application seems like it has been restarted. But some values are still remaining.. Please help..
public void addNewItem() {
LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item = li.inflate(R.layout.activity_order_items, null);
orderItemFrameView.add(item);
itemsLayout.addView(item);
setAdditionalFonts(item);
}
private void setAdditionalFonts(View view) {
TextView lblNameTak = (TextView)view.findViewById(R.id.tak_itemNo);
AutoCompleteTextView txtNameTak = (AutoCompleteTextView)view.findViewById(R.id.tak_itemName);
ImageView barScan = (ImageView)view.findViewById(R.id.barcode_scan);
TextView lblRate = (TextView)view.findViewById(R.id.tak_lblRate);
TextView lblQty = (TextView)view.findViewById(R.id.tak_lblQty);
TextView lblTotal = (TextView)view.findViewById(R.id.tak_lblTotal);
TextView rate = (TextView)view.findViewById(R.id.tak_Rate);
EditText2 qty = (EditText2)view.findViewById(R.id.tak_Qty);
TextView total = (TextView)view.findViewById(R.id.tak_Total);
qty.totTextView = total;
qty.rateTextView = rate;
qty.orderTake = this;
qty.index = orderItemFrameView.size() - 1;
qty.sqlDb = SqlDb;
qty.itemName = txtNameTak;
setupBarcodeScan(barScan);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/ubuntu-l.ttf");
Typeface tf2 = Typeface.createFromAsset(getAssets(), "fonts/calibri.ttf");
Typeface tf3 = Typeface.createFromAsset(getAssets(), "fonts/ubu-r.ttf");
Typeface tf4 = Typeface.createFromAsset(getAssets(), "fonts/tahoma.ttf");
lblNameTak.setTypeface(tf3);
txtNameTak.setTypeface(tf2);
lblRate.setTypeface(tf2);
lblQty.setTypeface(tf2);
lblTotal.setTypeface(tf2);
lblNameTak.setText("Item " + (qty.index + 1));
DbAdapterItem dbItem;
TextAdapterItem txtItem;
dbItem = new DbAdapterItem(this, SqlDb);
txtItem = new TextAdapterItem(dbItem, this, qty);
txtNameTak.setAdapter(txtItem);
txtNameTak.setOnItemClickListener(txtItem);
txtNameTak.requestFocus();
}
all these items created by addNewItem() are vanished...
here is the layout from which i'm inflating...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom ="22dp"
tools:context=".OrderItems" >
<FrameLayout
android:layout_width="match_parent"
android:background= "#888888"
android:layout_height="98dp" >
<TextView
android:id="#+id/tak_itemNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_marginTop="2.7dp"
android:text="Item 1"
android:layout_gravity="right"
android:textColor="#DDDDDD" />
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="22dp"
android:orientation="vertical"
android:background= "#FFFFFF"
android:layout_height="75dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<AutoCompleteTextView
android:id="#+id/tak_itemName"
android:imeOptions="actionUnspecified"
android:imeActionLabel="search"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="0dp"
android:layout_weight="1.06"
android:completionThreshold="1"
android:ems="10"
android:hint="Item Name / Barcode"
android:inputType="textCapWords"
android:singleLine="true"
android:textColorHint="#DDDDDD" />
<ImageView
android:id="#+id/barcode_scan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="7dp"
android:paddingRight="7dp"
android:paddingTop="6dp"
android:src="#android:drawable/ic_menu_camera" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
>
<TextView
android:id="#+id/tak_lblRate"
android:layout_width="wrap_content"
android:layout_marginLeft="7dp"
android:layout_height="wrap_content"
android:textColor="#555555"
android:textSize="10sp"
android:text="Rate" />
<TextView
android:id="#+id/tak_Rate"
android:layout_width="match_parent"
android:layout_marginTop="12dp"
android:layout_marginRight="15dp"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="16sp"
android:text="0.00" />
</FrameLayout>
<FrameLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
>
<TextView
android:id="#+id/tak_lblQty"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginRight="7dp"
android:layout_height="wrap_content"
android:textColor="#555555"
android:textSize="10sp"
android:text="Qty" />
<com.sayka.ordergadget.EditText2
android:id="#+id/tak_Qty"
android:layout_width="match_parent"
android:layout_marginBottom="-4dp"
android:layout_marginTop="4dp"
android:inputType="numberDecimal"
android:imeOptions="actionNext"
android:layout_marginLeft="12dp"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="16sp"
android:text="0.0" />
</FrameLayout>
<FrameLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
>
<TextView
android:id="#+id/tak_lblTotal"
android:layout_width="wrap_content"
android:layout_marginLeft="7dp"
android:layout_gravity="left"
android:layout_height="wrap_content"
android:textColor="#555555"
android:textSize="10sp"
android:text="Total" />
<TextView
android:id="#+id/tak_Total"
android:layout_width="match_parent"
android:layout_gravity="right"
android:layout_marginTop="12dp"
android:layout_marginRight="15dp"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="16sp"
android:text="0.00" />
</FrameLayout>
</FrameLayout>
</LinearLayout>
</FrameLayout>
It's normal behaviour and you are correct. the activity is recreated from scratch on rotation.
If you want something to persist. store it during onSaveInstanceState in the provided bundle.
then during onCreate check to see if the bundle is null, if it isn't, pull your data out and add the view elements again.
Alternatively you can fudge it and state in the manifest that your activity will handle orientation/configuration changes.