Edit text save text after reopen fragment - android

Hi all i have a problem with edit text in frament. This elemtn save text after reopening this fragment. It can reproduce if i do this steps
open activity -> open FragmentA ->open FragmentB (with edittext in it)->backPress(and open again FragmentA) -> open FragmentB (again)
After this steps if i am typed before some text its fill it again. I am add this in code: writeReviewText.setText(""); and in xml : android:text="" but nothing helps. It`s look like state of fragment is saves.
Here the code of xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/app_bar_gradient"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#android:color/transparent"
app:layout_scrollFlags="enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/greyReview">
<ScrollView
android:id="#+id/scrollReview"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<FrameLayout
android:id="#+id/recomendRev"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_weight="1">
<ImageButton
android:id="#+id/leftIb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:src="#drawable/review_recomend_left_selector" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:alpha="0.5"
android:src="#drawable/good" />
<TextView
android:id="#+id/leftTv"
style="#style/Base.TextAppearance.AppCompat.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="2dp"
android:background="#android:color/transparent"
android:text="#string/recomend"
android:textColor="#color/fiolet" />
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="#+id/noRecomendRev"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginRight="5dp"
android:layout_weight="1">
<ImageButton
android:id="#+id/rightIb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:src="#drawable/review_recomend_right_selector" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right|bottom"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:alpha="0.5"
android:src="#drawable/bad" />
<TextView
android:id="#+id/rightTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="2dp"
android:background="#android:color/transparent"
android:text="#string/dontRecomended"
android:textColor="#color/fiolet" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
<EditText
android:id="#+id/writeReviewText"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="5dp"
android:background="#android:color/white"
android:hint="#string/dummyReview"
android:inputType="textCapSentences|textMultiLine"
android:maxLength="2000"
android:text=""
android:maxLines="4" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:background="#color/darkGreyReview">
<include
android:id="#+id/photosDummy"
layout="#layout/add_photo_dummy"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</include>
<android.support.v7.widget.RecyclerView
android:id="#+id/photosRv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:visibility="gone" />
</FrameLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
Here a code of my fragment class:
public class WriteReviewFragment extends Fragment implements Constants, View.OnClickListener, ExpandableListView.OnChildClickListener, CameraInterface {
MainActivity mActivity;
View self;
EditText writeReviewText;
public int GetPixelFromDips(float pixels) {
// Get the screen's density scale
final float scale = getResources().getDisplayMetrics().density;
// Convert the dps to pixels, based on density scale
return (int) (pixels * scale + 0.5f);
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.e(TAG, "onCreateView");
self = inflater.inflate(R.layout.write_review_layout, container, false);
mActivity = ((MainActivity) getActivity());
font = DialogsHelper.getRLight(getActivity().getApplicationContext());
user = mActivity.getUser();
width = DialogsHelper.getDisplayWidth(mActivity);
currentlocale = getResources().getConfiguration().locale;
return self;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
Log.e(TAG, "onViewCreated");
super.onViewCreated(view, savedInstanceState);
Toolbar tv = (Toolbar) view.findViewById(R.id.toolbar);
TextView tbTv = (TextView) tv.findViewById(R.id.tolbarTv);
TextView post = (TextView) tv.findViewById(R.id.post);
back = (ImageView) tv.findViewById(R.id.back);
post.setTypeface(font);
tbTv.setTypeface(font);
tags = (RecipientEditTextView) view.findViewById(R.id.chipsView);
tags.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
tags.setAdapter(new BaseRecipientAdapter(getActivity()));
tags.setTypeface(font);
musicExLv = (ExpandableListView) self.findViewById(R.id.expandableListView);
peopleAVGExLv = (ExpandableListView) self.findViewById(R.id.expandableListViewAVG);
peopleIm = (ImageView) self.findViewById(R.id.peopleIm);
musicIm = (ImageView) self.findViewById(R.id.musicIm);
photosDummy = (RelativeLayout) self.findViewById(R.id.photosDummy);
photosRv = (RecyclerView) self.findViewById(R.id.photosRv);
avgpeople = (TextView) self.findViewById(R.id.avgpeople);
musictype = (TextView) self.findViewById(R.id.musictype);
faceControl = (TextView) self.findViewById(R.id.faceControl);
dresCode = (TextView) self.findViewById(R.id.dresCode);
details = (TextView) self.findViewById(R.id.details);
tagsTv = (TextView) self.findViewById(R.id.tags);
rightTv = (TextView) self.findViewById(R.id.rightTv);
leftTv = (TextView) self.findViewById(R.id.leftTv);
writeReviewText = (EditText) self.findViewById(R.id.writeReviewText);
noRecomendRev = (ImageButton) self.findViewById(R.id.rightIb);
recomendRev = (ImageButton) self.findViewById(R.id.leftIb);
dresleftIb = (ImageButton) self.findViewById(R.id.dresleftIb);
dresRightIb = (ImageButton) self.findViewById(R.id.dresRightIb);
faceleftIb = (ImageButton) self.findViewById(R.id.faceleftIb);
faceRightIb = (ImageButton) self.findViewById(R.id.faceRightIb);
faceRightTv = (TextView) self.findViewById(R.id.faceRightTv);
faceleftTv = (TextView) self.findViewById(R.id.faceleftTv);
dresrightTv = (TextView) self.findViewById(R.id.dresrightTv);
dresleftTv = (TextView) self.findViewById(R.id.dresleftTv);
post.setOnClickListener(this);
back.setOnClickListener(this);
dresleftIb.setOnClickListener(this);
dresRightIb.setOnClickListener(this);
faceleftIb.setOnClickListener(this);
faceRightIb.setOnClickListener(this);
noRecomendRev.setOnClickListener(this);
recomendRev.setOnClickListener(this);
photosDummy.setOnClickListener(this);
peopleIm.setOnClickListener(this);
musicIm.setOnClickListener(this);
writeReviewText.setTypeface(font);
avgpeople.setTypeface(font);
musictype.setTypeface(font);
faceControl.setTypeface(font);
dresCode.setTypeface(font);
details.setTypeface(font);
tagsTv.setTypeface(font);
rightTv.setTypeface(font);
leftTv.setTypeface(font);
faceRightTv.setTypeface(font);
faceleftTv.setTypeface(font);
dresrightTv.setTypeface(font);
dresleftTv.setTypeface(font);
StaggeredGridLayoutManager sglm = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.HORIZONTAL);
photosRv.setLayoutManager(sglm);
//set same size as images preview
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, width / screenPart);
Log.e(TAG, "photosDummy" + (width / screenPart));
photosDummy.setLayoutParams(lp);
if (getArguments() != null) {
Bundle b = getArguments();
if (b.containsKey("foursquare_id")) {
foursquare_id = b.getString("foursquare_id").toString();
} else {
Toast.makeText(getActivity(), "FSQ Id is empty, you can`t post anything", Toast.LENGTH_SHORT).show();
}
}
//change state of arrow marker
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR2) {
musicExLv.setIndicatorBoundsRelative(width - GetPixelFromDips(30), width - GetPixelFromDips(10));
peopleAVGExLv.setIndicatorBoundsRelative(width - GetPixelFromDips(30), width - GetPixelFromDips(10));
} else {
musicExLv.setIndicatorBounds(width - GetPixelFromDips(30), width - GetPixelFromDips(10));
peopleAVGExLv.setIndicatorBounds(width - GetPixelFromDips(30), width - GetPixelFromDips(10));
}
prepareMusicList();
preparePeopleList();
writeReviewText.setText("");
writeReviewText.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
reviewAdd.setReview_text(s.toString());
}
});
}
And here code how i am open fragment in activity:
public void SetCurentFragment(final int index, int direction, boolean addToBackStack, int type, Bundle bundle) {
if (currentIndex != 5) {
previosIndex = currentIndex;
}
if (index == 1 || index == 2)
DeleteAllFragmentsBackstack();// need for detect if google map is initialize and already in backstack
Fragment fragment;
fragment = getSupportFragmentManager().findFragmentByTag(ReadReviewFragment.class.getClass().getSimpleName());
if (fragment == null) {
if (fragment == null) {
fragment = fragmentArray[index];
}
} else {
fragment = fragmentArray[index];
}
Log.e(TAG, "Open fragment is " + fragment);
if (fragment.getArguments() != null) {
fragment.getArguments().clear(); //for clear arguments if they saved from previous open of fragment(happens when open photos fragment)
}
if (bundle != null) {
if (fragment.getArguments() == null) {
fragment.setArguments(bundle);
} else {
fragment.getArguments().clear();
fragment.setArguments(bundle);
}
}
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.container, fragment, fragment.getClass().getSimpleName());
if (addToBackStack) {
transaction.addToBackStack(fragment.getTag());
} else {
transaction.addToBackStack(null);
}
transaction.commitAllowingStateLoss();
Log.e(TAG, "Transaction commit");
currentIndex = index;
if (index == 0 || index == 1 || index == 2) {
SetVisualTabs(index);
}
}
I am debug my code and bundle is empty when i am open FragmentB. And fragmentArray its array of fragments like:
public final Fragment[] fragmentArray = new Fragment[]{
new FragmentA(),//0
new FragmentB(),//1

Related

Fragment editText data getting cleared when i am moving to another activity and coming back

I have an FragmentActivity which contain WebView, Edittext1, Edittext2, Checkboxes and button. When I click the button in fragment it will move to Results_activity. And if I click button from Results_activity it move back to FragmentActivity.
But my edittext values getting cleared while moving back.
FragmentActivity xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#android:color/background_light"
android:orientation="vertical">
<LinearLayout
android:id="#+id/questionContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<WebView
android:id="#+id/questionWV"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="#+id/ansA_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp">
<EditText
android:id="#+id/ansA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:freezesText="true"
android:hint="Enter answer here..."
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:textAppearance="#android:style/TextAppearance.Medium" />
</LinearLayout>
<LinearLayout
android:id="#+id/ansB_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp">
<EditText
android:id="#+id/ansB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:freezesText="true"
android:hint="Enter answer here..."
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:textAppearance="#android:style/TextAppearance.Medium" />
</LinearLayout>
<LinearLayout
android:id="#+id/answers_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp">
<RelativeLayout
android:id="#+id/answer_a_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_weight="1">
<CheckBox
android:id="#+id/answerA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:hint="0"
android:maxLines="100"
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:text="Varianta A"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/answer_b_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<CheckBox
android:id="#+id/answerB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="false"
android:layout_marginStart="15dp"
android:hint="1"
android:maxLines="100"
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:text="Varianta B"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/answer_c_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<CheckBox
android:id="#+id/answerC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:hint="2"
android:maxLines="100"
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:text="Varianta C"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/answer_d_container"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<CheckBox
android:id="#+id/answerD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:hint="3"
android:maxLines="100"
android:minWidth="50dp"
android:minHeight="50dp"
android:scrollbars="vertical"
android:text="Varianta D"
android:textAppearance="#android:style/TextAppearance.Medium" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom|center"
android:orientation="horizontal"
android:paddingBottom="30dp">
<Button
android:id="#+id/btnFinishTest"
style="#android:style/Widget.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/testbutton"
android:onClick="FinishTest"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Finish Test" />
<Button
android:id="#+id/btnAnswer"
style="#android:style/Widget.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/testbutton"
android:onClick="SubmitAnswer"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Submit Answer" />
</LinearLayout>
</LinearLayout>
Fragment Code
my edittexts are et1 and et2
public class QuestionFragment2018ii extends Fragment {
LinearLayout answersContainer;
int currentPageNr;
private String input1;
#Override
public View onCreateView(LayoutInflater lInflater, ViewGroup container,Bundle saveInstanceState){
currentPageNr = getArguments().getInt("position");
//initialize some variables
final Question2018ii currentQuestion2018ii = MyServerData2018ii.getInstance().getQuestion(currentPageNr);
View rootView = lInflater.inflate(R.layout.quiz_activity_fragment,container,false);
//initialize show answer option
final String ans = currentQuestion2018ii.getExplanationText();
final EditText et1 = rootView.findViewById(R.id.ansA);
final EditText et2 = rootView.findViewById(R.id.ansB);
if(MyServerData2018ii.getInstance().getTestState().equals("finished") ){
et1.setText("Your Response: " + et.getText());
et2.setText("Correct Answer: " + ans);
}
//initialize Explanation option
//initialize answers
answersContainer = (LinearLayout)rootView.findViewById(R.id.answers_container);
String[] answers = currentQuestion2018ii.getAllAnswersText();
for (int i = 0; i < answersContainer.getChildCount(); i++) {
RelativeLayout checkboxContainer = (RelativeLayout)answersContainer.getChildAt(i);
CheckBox cb = (CheckBox)checkboxContainer.getChildAt(0);
cb.setMovementMethod(new ScrollingMovementMethod());
cb.setText(answers[i]);
cb.setChecked(currentQuestion2018ii.isChecked(i));
if(MyServerData2018ii.getInstance().getTestState().equals("finished") ){
cb.setEnabled(false);
questionWebView.loadUrl("file:///android_asset/" + currentQuestion2018ii.getSolutionText());
//check if answer is right or wrong
if(currentQuestion2018ii.isCorrectAnswer(i)){
cb.setTextColor(Color.parseColor("#4DAD47"));
cb.setTypeface(null, Typeface.BOLD);
} else {
cb.setTextColor(Color.parseColor("#CE0B0B"));
}
}else{
cb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CheckBox cb = ((CheckBox) v);
int number = Integer.parseInt(cb.getHint().toString());
currentQuestion2018ii.setChecked(number, cb.isChecked());
}
});
}
}
return rootView;
}
}
ResultsActivity xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingBottom="10dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="30dp"
android:text="#string/results"
android:textColor="#4DAD47"
android:textSize="20sp"
android:textStyle="bold|italic" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingTop="30dp" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:paddingBottom="20dp"
android:text="#string/correct_answers" />
</LinearLayout>
<TextView
android:id="#+id/myTotalAnswers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:paddingRight="5dp"
android:text="50/100" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainContainer"></LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<Button
android:id="#+id/check_results"
style="#android:style/Widget.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#drawable/testbutton"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/check_results" />
<Button
android:id="#+id/btnMainMenu"
style="#android:style/Widget.Button.Inset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#drawable/testbutton"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="#string/main_menu" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
Quiz activity
public class QuizActivity2018ii extends AppCompatActivity {
Spinner spinCategory;
EditText questionNr;
ArrayList<String> allCategories;
int totalQuestions;
AlertDialog dialog;
ViewPager pager;
QuestionPagerAdapter2018ii pagerAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.quiz_activity_view_pager);
allCategories = new ArrayList<>(MyServerData2018ii.getInstance().getCategoryList());
totalQuestions = MyServerData2018ii.getInstance().getTotalQuestions();
//initialize category spinner
ArrayAdapter<String> categoryAdapter = new ArrayAdapter<>(this,android.R.layout.simple_spinner_dropdown_item,allCategories);
spinCategory = (Spinner) findViewById(R.id.category);
spinCategory.setAdapter(categoryAdapter);
spinCategory.setSelection(0);
//set Category spinner callback
spinCategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String currentQuestionRealCategory = MyServerData2018ii.getInstance().getQuestionCategory(pager.getCurrentItem());
String selectedCategory = spinCategory.getItemAtPosition(position).toString();
if (!selectedCategory.equals(currentQuestionRealCategory)) {
int firstQuestionNumberFromCategory = MyServerData2018ii.getInstance().getFirstQuestionNumberFromCategory(selectedCategory);
ViewPager pager = (ViewPager) findViewById(R.id.qPager);
pager.setCurrentItem(firstQuestionNumberFromCategory, false);
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
//initialize number
questionNr = (EditText) findViewById(R.id.dialog_question_number);
questionNr.clearFocus();
//set number callbacks
questionNr.setOnKeyListener(new View.OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_ENTER)) {
v.clearFocus();
CharSequence s = questionNr.getText();
if (!s.toString().isEmpty()) {
Integer questionNumber = Integer.parseInt(s.toString());
//avoids out of range indexes
if (questionNumber > totalQuestions + 1) {
questionNumber = totalQuestions;
}
if (questionNumber < 0) {
questionNumber = 1;
}
//create looping effect
if (questionNumber == totalQuestions + 1) {
questionNumber = 1;
((EditText)v).setText("1");
}
if (questionNumber == 0) {
questionNumber = totalQuestions;
((EditText)v).setText(String.valueOf(totalQuestions));
}
ViewPager pager = (ViewPager) findViewById(R.id.qPager);
pager.setCurrentItem(questionNumber, false);
questionNr.clearFocus();
} else {
questionNr.setText("1");
}
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
return false;
}
});
//initialize pager
pager = (ViewPager)findViewById(R.id.qPager);
pagerAdapter = new QuestionPagerAdapter2018ii(getSupportFragmentManager());
pager.setAdapter(pagerAdapter);
pager.setCurrentItem(1, false);
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
#Override
public void onPageSelected(int position) {
Integer currentQuestion = pager.getCurrentItem();
//change spinner
String currentCategory = MyServerData2018ii.getInstance().getQuestionCategory(currentQuestion);
int categoryPosition = MyServerData2018ii.getInstance().getCategoryList().indexOf(currentCategory);
spinCategory.setSelection(categoryPosition);
//change numberPicker
if(currentQuestion <= 0){currentQuestion = totalQuestions;}
if(currentQuestion > totalQuestions){currentQuestion = 1;}
questionNr.setText(currentQuestion.toString());
questionNr.clearFocus();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(questionNr.getWindowToken(), 0);
}
#Override
public void onPageScrollStateChanged(int state) {
int totalQuestions = MyServerData2018ii.getInstance().getTotalQuestions();
if (state == ViewPager.SCROLL_STATE_IDLE) {
if (pager.getCurrentItem() == totalQuestions + 1) {
pager.setCurrentItem(1, false);
}
if (pager.getCurrentItem() == 0) {
pager.setCurrentItem(totalQuestions, false); // false will prevent sliding animation of view pager
}
}
}
});
}
public void FinishTest(View v){
//check if there are unanswered questions
if(MyServerData2018ii.getInstance().getTestState().equals("inProgress")){
ArrayList<String> UnansweredQuestions = new ArrayList<>();
LinkedHashMap<String,Object> allQuestions = MyServerData2018ii.getInstance().getAllQuestions();
for(Map.Entry category: allQuestions.entrySet()){
Question2018ii[] question2018iis = (Question2018ii[])category.getValue();
for(int i = 0; i < question2018iis.length; i++){
Boolean[] userAnswers = question2018iis[i].getUserAnswers();
if(!Arrays.asList(userAnswers).contains(true)){
String checkedCategory = (String)category.getKey();
Integer questionNumberInList = MyServerData2018ii.getInstance().getQuestionListNumber(checkedCategory,i);
UnansweredQuestions.add(String.valueOf(questionNumberInList));
}
}
}
if(UnansweredQuestions.size() > 0){
dialog = new AlertDialog.Builder(this)
.create();
LayoutInflater infl = LayoutInflater.from(this);
dialog.setView(infl.inflate(R.layout.dialog_message,null));
dialog.show();
TextView message = (TextView)dialog.findViewById(R.id.message);
String unfinished = getResources().getString(R.string.unfinished_text);
String questions = TextUtils.join(",",UnansweredQuestions);
message.setText(unfinished + "\n" + questions + ".");
dialog.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
showResults();
}
});
}else{showResults();}
}else{
showResults();
}
}
public void showResults(){
int animationDuration;
if(MyServerData2018ii.getInstance().getTestState().equals("finished")){
animationDuration = 10;
}else{
animationDuration = 2000;
}
View mainView = LayoutInflater.from(this).inflate(R.layout.quiz_activity_show_results,null);
LinearLayout mainContainer = (LinearLayout)mainView.findViewById(R.id.mainContainer);
mainView.findViewById(R.id.btnMainMenu).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//finish the test and go to main menu
Intent Main = new Intent(getApplicationContext(),MainActivity.class);
finish();
startActivity(Main);
MyServerData2018ii.getInstance().setTestState("notStarted");
MyServerData2018ii.getInstance().clearAnswers();
Toast.makeText(getBaseContext(),R.string.text_ended,Toast.LENGTH_LONG).show();
}
});
mainView.findViewById(R.id.check_results).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = getIntent();
finish();
startActivity(intent);
}
});
Question2018ii[] currentCategory;
int totalCategoryQuestions;
int correctCategoryQuestions;
int totalCorrectQuestions = 0;
//checking and adding each category
for(String category: allCategories){
View categoryContainer = LayoutInflater.from(this).inflate(R.layout.quiz_activity_category_results,null);
TextView categoryName = (TextView)categoryContainer.findViewById(R.id.categoryName);
//set name
categoryName.setText(category);
currentCategory = MyServerData2018ii.getInstance().getCategory(category);
totalCategoryQuestions = currentCategory.length;
//check answers
correctCategoryQuestions = 0;
for(int i=0; i < currentCategory.length;i++){
Boolean isCorrect = Arrays.equals(currentCategory[i].getAllCorrectAnswers(),currentCategory[i].getUserAnswers());
if(isCorrect){ correctCategoryQuestions++;}
}
totalCorrectQuestions += correctCategoryQuestions;
//set results
String result = String.valueOf(correctCategoryQuestions) + "/" + String.valueOf(totalCategoryQuestions);
final ProgressBar progress = (ProgressBar)categoryContainer.findViewById(R.id.progressBar);
progress.setMax(totalCategoryQuestions*100);
final TextView myResult = (TextView)categoryContainer.findViewById(R.id.categoryResult);
final String myResultText = "/" + String.valueOf(totalCategoryQuestions);
ValueAnimator val = new ValueAnimator();
val.setObjectValues(0, correctCategoryQuestions*100);
val.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
myResult.setText(String.valueOf((Integer)animation.getAnimatedValue()/100) + myResultText);
progress.setProgress( ((Integer) animation.getAnimatedValue()));
}
});
val.setDuration(animationDuration);
val.start();
mainContainer.addView(categoryContainer);
}
//animate results
final TextView tvTotalResult =(TextView)mainView.findViewById(R.id.myTotalAnswers);
final String totalResultS = "/" + String.valueOf(totalQuestions);
ValueAnimator totalResultsAnimator = new ValueAnimator();
totalResultsAnimator.setObjectValues(0, totalCorrectQuestions);
totalResultsAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
tvTotalResult.setText(String.valueOf(animation.getAnimatedValue()) + totalResultS);
}
});
totalResultsAnimator.setDuration(animationDuration);
totalResultsAnimator.start();
MyServerData2018ii.getInstance().setTestState("finished");
setContentView(mainView);
}
}
this is my question yearwise activity(from this I launched the fragment activity)
public class QuestionYearwise extends AppCompatActivity{
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.question_yearwise);
Button btn2018ii = (Button)findViewById(R.id.btn2018ii);
btn2018ii.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent Quiz2018ii = new Intent(getApplicationContext(),QuizActivity2018ii.class);
MyServerData2018ii.getInstance().setTestState("inProgress");
startActivity(Quiz2018ii);
}
});
}
}
Replace the method like this,
mainView.findViewById(R.id.check_results).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});

TextView text overlapping when orientation changes

I have a TextView for description and another one for current step " app for
recipes "
When i changed orientation of device to landscape and returning to portrait mode again this problem happen ( text in TextView come like another TextView not same although there is single TextView and this overlapping happen ) see attached images .
Normal view before changing orientation
This when i go landscape and returned to portrait again
Xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="#+id/playerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<ImageView
android:id="#+id/thumbImage"
android:layout_gravity="left"
android:paddingRight="15dp"
android:elevation="1dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="16dp"
android:textSize="17sp"
android:text="intro"
android:freezesText="true"
android:gravity="center_horizontal"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.design.widget.FloatingActionButton
android:id="#+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_next"
android:layout_alignParentRight="true"
app:fabSize="auto" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_back"
app:fabSize="auto" />
<TextView
android:id="#+id/currentStep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="1/10"
android:textSize="20sp"/>
</RelativeLayout>
</LinearLayout>
Java Code :
public class StepDetailsFragment extends android.app.Fragment implements View.OnClickListener {
ArrayList<Step> steps;
StepsAdapter adapter;
#BindView(R.id.description)
TextView description;
#BindView(R.id.currentStep)
TextView current;
#BindView(R.id.next_button)
FloatingActionButton next;
#BindView(R.id.back_button)
FloatingActionButton back;
FragmentOneListener listener;
public int currentIndex;
#BindView(R.id.playerView)
SimpleExoPlayerView playerView;
SimpleExoPlayer player;
private boolean playWhenReady=true;
private long playbackPosition;
private int currentWindow;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.details_fragment, container, false);
ButterKnife.bind(this, root);
Bundle bundle = getArguments();
if (!bundle.containsKey("steps")) {
return root;
}
steps = bundle.getParcelableArrayList("steps");
currentIndex = bundle.getInt("current");
show();
back.setOnClickListener(this);
next.setOnClickListener(this);
return root;
}
#Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.back_button) {
currentIndex--;
show();
} else if (id == R.id.next_button) {
currentIndex++;
show();
}
}
public void show() {
if (currentIndex <= 0) {
back.setVisibility(GONE);
} else {
back.setVisibility(View.VISIBLE);
}
if (listener != null) {
listener.setCurrent(currentIndex);
}
if (currentIndex >= steps.size() - 1) {
next.setVisibility(GONE);
} else {
next.setVisibility(View.VISIBLE);
}
description.setText(steps.get(currentIndex).getDescription());
current.setText((currentIndex + 1) + "/" + steps.size());
}
Your activity is recreated on rotation.
The fragment manager stores the original fragment in the instance state, but I assume you are adding a new fragment in the onCreate() of the activity.
So you have the restored and the new fragment on top of each other.
Perhaps only add a new fragment if savedInstanceState is null.

Android click on view above the view

I have tab Layout with dynamically added custom tabs (Image View + Text View)
I want to change image on select tab and on reselect (2 kind of images)
But there is no click event listeners on Tab, so I added transparent layout to catch clicks.
How do I need to change settings, to make 4 Linear Layouts clickable?
The code:
<RelativeLayout
android:id="#+id/layout_sort_bar_fc"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true">
<android.support.design.widget.TabLayout
android:id="#+id/sort_bar_fc"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabBackground="#color/colorPrimary"
app:tabIndicatorColor="#f00"
app:tabSelectedTextColor="#color/white_text"
app:tabTextColor="#color/colorPrimaryDark"/>
<LinearLayout
android:id="#+id/tab_listenter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/dummy_tab_name"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0"
android:clickable="true"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:id="#+id/dummy_tab_rate"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:id="#+id/dummy_tab_change"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:id="#+id/dummy_tab_24h"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0"
android:orientation="horizontal"></LinearLayout>
</LinearLayout>
</RelativeLayout>
the following answer deals with somewhat the same question and the answer marked as solution is what you're looking for, it explains how to define and use selectors
Well, you can change image on a selected tab by two method which you need to create in Custom Pager Adapter and call it from tab selected listener.
"MainActivity"
public class MainActivity extends AppCompatActivity {
TabLayout tabLayout;
ViewPager viewPager;
ViewPagerAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.viewpager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
createViewPager(viewPager);
tabLayout.setupWithViewPager(viewPager);
createTabIcons();
adapter.SetOnSelectView(tabLayout,0);
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
int c = tab.getPosition();
adapter.SetOnSelectView(tabLayout,c);
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
int c = tab.getPosition();
adapter.SetUnSelectView(tabLayout,c);
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
for (int i = 0; i < tabLayout.getTabCount() - 1; i++) {
View tab = ((ViewGroup) tabLayout.getChildAt(0)).getChildAt(i);
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) tab.getLayoutParams();
p.setMargins(0, 0, 10, 0);
tab.requestLayout();
}
}
private void createTabIcons() {
try {
View tabOne = LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
TextView textView = tabOne.findViewById(R.id.tab);
ImageView imgViewTabIcon = tabOne.findViewById(R.id.imgViewTabIcon);
imgViewTabIcon.setImageResource(R.drawable.img_11);
textView.setText("A");
tabLayout.getTabAt(0).setCustomView(tabOne);
View tabTwo = LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
TextView textView1 = tabTwo.findViewById(R.id.imgViewTabIcon);
textView1.setText("B");
ImageView imgViewTabIcon1 = tabTwo.findViewById(R.id.imgViewTabIcon);
imgViewTabIcon1.setImageResource(R.drawable.img_22);
tabLayout.getTabAt(1).setCustomView(tabTwo);
View tabThree = LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
TextView textView2 = tabThree.findViewById(R.id.tab);
textView2.setText("C");
ImageView imgViewTabIcon2 = tabThree.findViewById(R.id.imgViewTabIcon);
imgViewTabIcon2.setImageResource(R.drawable.img_33);
tabLayout.getTabAt(2).setCustomView(tabThree);
View tabFour = LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
TextView textView3 = tabFour.findViewById(R.id.tab);
textView3.setText("D");
ImageView imgViewTabIcon3 = tabFour.findViewById(R.id.imgViewTabIcon);
imgViewTabIcon3.setImageResource(R.drawable.img_33);
tabLayout.getTabAt(3).setCustomView(tabFour);
} catch (Exception e) {
e.printStackTrace();
}
}
private void createViewPager(ViewPager viewPager) {
adapter = new ViewPagerAdapter(getSupportFragmentManager(),HomeActivity.this);
adapter.addFrag(new A(), "A");
adapter.addFrag(new B(), "B");
adapter.addFrag(new C(), "C");
adapter.addFrag(new D(), "D");
viewPager.setAdapter(adapter);
}
}
"Custom PagerAdapter"
public class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
private Context mContext;
public ViewPagerAdapter(FragmentManager manager, Context context) {
super(manager);
mContext=context;
}
#Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
#Override
public int getCount() {
return mFragmentList.size();
}
public void addFrag(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
public int dpToPx(int dp) {
DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
return Math.round(dp * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));
}
public void SetOnSelectView(TabLayout tabLayout, int position)
{
TabLayout.Tab tab = tabLayout.getTabAt(position);
View selected = tab.getCustomView();
TextView textView = (TextView) selected.findViewById(R.id.tab);
textView.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
ImageView imgViewTabIcon = selected.findViewById(R.id.imgViewTabIcon);
int height = dpToPx(35);
if(textView.getText().toString().equals("tab1")){
BitmapDrawable bitmapdraw = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.img_1);
Bitmap b = bitmapdraw.getBitmap();
Bitmap smallMarker = Bitmap.createScaledBitmap(b, height, height, false);
imgViewTabIcon.setImageBitmap(smallMarker);
}else if(textView.getText().toString().equals("tab2")){
BitmapDrawable bitmapdraw = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.img_2);
Bitmap b = bitmapdraw.getBitmap();
Bitmap smallMarker = Bitmap.createScaledBitmap(b, height, height, false);
imgViewTabIcon.setImageBitmap(smallMarker);
}else if(textView.getText().toString().equals("tab3")){
BitmapDrawable bitmapdraw = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.img_3);
Bitmap b = bitmapdraw.getBitmap();
Bitmap smallMarker = Bitmap.createScaledBitmap(b, height, height, false);
imgViewTabIcon.setImageBitmap(smallMarker);
}
else {
BitmapDrawable bitmapdraw = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.img_4);
Bitmap b = bitmapdraw.getBitmap();
Bitmap smallMarker = Bitmap.createScaledBitmap(b, height, height, false);
imgViewTabIcon.setImageBitmap(smallMarker);
}
}
public void SetUnSelectView(TabLayout tabLayout,int position) {
TabLayout.Tab tab = tabLayout.getTabAt(position);
View selected = tab.getCustomView();
TextView textView = (TextView) selected.findViewById(R.id.tab);
textView.setTextColor(mContext.getResources().getColor(R.color.white));
ImageView imgViewTabIcon = selected.findViewById(R.id.imgViewTabIcon);
if(textView.getText().toString().equals("tab1")){
imgViewTabIcon.setImageResource(R.drawable.img_11);
}else if(textView.getText().toString().equals("tab2")){
imgViewTabIcon.setImageResource(R.drawable.img_22);
}else if(textView.getText().toString().equals("tab3")){
imgViewTabIcon.setImageResource(R.drawable.img_33);
}else{
imgViewTabIcon.setImageResource(R.drawable.img_44);
}
}
#Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
#Override
public int getItemPosition(Object object){
return ViewPagerAdapter.POSITION_NONE;
}
}
"Custom Layout for Tab"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/custom_tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/tab_color_selector"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center">
<ImageView
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:id="#+id/imgViewTabIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/img_11" />
<TextView
android:id="#+id/tab"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"
android:textColor="#FFFFFF"
android:layout_gravity="center"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
"MainActivity XML File"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#drawable/bg"
android:orientation="vertical"
tools:context=".activity.MainActivity">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
app:tabBackground="#drawable/tab_color_selector"
app:tabGravity="fill"
app:tabIndicatorColor="#color/gps_btn"
app:tabMode="fixed"
app:tabSelectedTextColor="#ffffff"
app:tabTextColor="#ffffff" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</LinearLayout>

Fragment doesn't respect match parent height when having listview row item has hidden view in it

I am having a weird issue in my app. In one of my app activity I am inflating three fragments in it with tabs. Everything works fine.
In the fragment in which I am having problem, I have listview which is inflated using adapter and data fro web service. This also works well. Now the problem is this the row which is inflated in adapter, has a hidden view which has visibility=gone in xml. On tap of imageview from that row I make that layout visible through java code. The problem is layout doesn't become visible on tap. I have even set breakpoint on the onClickListener of imageview and it does execute the line which changes the visibility from gone to visible. I am unable to understand what is causing this issue as I am using the same row xml with same data in other screen and there it is working perfectly.
UPDATE
I got to know what's causing this issue but don't know how to solve this. In my activity I am having three fragments. The view that I provided for fragment(in which fragment will be inflated) is causing main problem. I have set height width to match parent but it is not taking match parent height. If the fragment just includes normal views like textview, imageview then also fragment is shown properly.But the problem is if fragment consists of listview, then it only takes height of the custom row that is supplied to the listview. I am able to scroll complete listview in that space.
I don't understand what is causing this behaviour.
My Updated code.
Main layout xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<include layout="#layout/header_1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#000"
android:weightSum="3"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:weightSum="1"
android:orientation="horizontal"
android:id="#+id/lin_birds">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="#string/aves"
android:textColor="#ffffff"
android:gravity="center"
android:layout_gravity="center"
android:layout_weight="0.99"
android:id="#+id/fragment_aves"/>
<View
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="0.01"
android:background="#ffffff"
android:layout_marginTop="10dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:weightSum="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="#string/routes"
android:textColor="#ffffff"
android:gravity="center"
android:layout_gravity="center"
android:layout_weight="0.99"
android:id="#+id/fragment_routes"/>
<View
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="0.01"
android:background="#ffffff"
android:layout_marginTop="10dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/information"
android:textColor="#ffffff"
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/fragment_information"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frame_details" />
</LinearLayout>
</LinearLayout>
Main activity java code
public class ActivityRoutesDetails extends AppCompatActivity {
RelativeLayout rel_back;
TextView tv_title,tv_information,tv_routes,fragment_aves;
RoutesDataBean routesDataBean;
LinearLayout frame;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.routes_detail);
tv_title= (TextView)findViewById(R.id.tv_title);
tv_information= (TextView) findViewById(R.id.fragment_information);
tv_routes= (TextView) findViewById(R.id.fragment_routes);
fragment_aves= (TextView) findViewById(R.id.fragment_aves);
// frame= (LinearLayout) findViewById(R.id.frame_details);
routesDataBean= (RoutesDataBean)getIntent().getSerializableExtra("data");
tv_title.setText(routesDataBean.getDescrip1());
Fragment fragment=new FragmentRouteInside();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.frame_details, fragment);
fragmentTransaction.commit();
fragment_aves.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment fragmentBirds=new FragmentRouteBirds();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_details, fragmentBirds);
fragmentTransaction.commit();
}
});
tv_information.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment fragmentRouteInformation = new FragmentRouteInformation();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_details, fragmentRouteInformation);
fragmentTransaction.commit();
}
});
tv_routes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment fragment=new FragmentRouteInside();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_details, fragment);
fragmentTransaction.commit();
}
});
rel_back= (RelativeLayout) findViewById(R.id.rel_back);
rel_back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
}
fragment bird xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lv_bird"/>
</LinearLayout>
Fragment java code
public class FragmentRouteBirds extends Fragment {
AppSharedPreferences appSharedPreferences;
String REGISTER_URL="";
ListView lv_birds;
private ArrayList<BirdsDataBean> birdsUrlList;
boolean flag=false;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragments_birds, null);
appSharedPreferences=AppSharedPreferences.getsharedprefInstance(getActivity());
REGISTER_URL = "http://192.241.162.63/appvist/v1/routebird/"+appSharedPreferences.getRouteId();
birdsUrlList = new ArrayList<>();
lv_birds = (ListView) root.findViewById(R.id.lv_bird);
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) lv_birds.getLayoutParams();
lp.height = LinearLayout.LayoutParams.MATCH_PARENT;
lv_birds.setLayoutParams(lp);
hitBirdsService();
return root;
}
private void hitBirdsService() {
class RegisterUser extends AsyncTask<String, Void, String> {
private ProgressDialog mDialog;
RequestClass ruc = new RequestClass();
String response = "";
#Override
protected void onPreExecute() {
super.onPreExecute();
mDialog = new ProgressDialog(getActivity());
mDialog.setMessage("Please Wait ...");
mDialog.setCancelable(false);
mDialog.show();
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
mDialog.dismiss();
parseBirdResponse(response);
//Toast.makeText(getActivity(), s, Toast.LENGTH_LONG).show();
}
#Override
protected String doInBackground(String[] params) {
response = RequestClass.GET(REGISTER_URL);
return response;
}
}
RegisterUser ru = new RegisterUser();
ru.execute();
}
public void parseBirdResponse(String response) {
//String descrip, String observaciones, String descrip_larga, String url_video, String url
try {
JSONObject jsonObject = new JSONObject(response);
Boolean error = jsonObject.getBoolean("error");
if (!error) {
JSONArray jsonArray = jsonObject.getJSONArray("birds");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonBirds = jsonArray.getJSONObject(i);
int idave=jsonBirds.getInt("idave");
String descrip = jsonBirds.getString("descrip");
String observaciones = jsonBirds.getString("observaciones");
String descrip_larga = jsonBirds.getString("descrip_larga");
String url_video = jsonBirds.getString("url_video");
String url = jsonBirds.getString("url");
String nombre_cientifico = jsonBirds.getString("nombre_cientifico");
int flag=jsonBirds.getInt("flag");
birdsUrlList.add(new BirdsDataBean(flag,idave,descrip, observaciones, descrip_larga, url_video, url, nombre_cientifico));
}
ScheduleTaskAdapter scheduleTaskAdapter = new ScheduleTaskAdapter(getActivity(), birdsUrlList);
lv_birds.setAdapter(scheduleTaskAdapter);
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) lv_birds.getLayoutParams();
lp.height = 800;
lv_birds.setLayoutParams(lp);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
public class ScheduleTaskAdapter extends BaseAdapter {
Context context;
LayoutInflater layoutInflater;
// List<InterestAndLanguageBean> interestAndLanguageBeans=new ArrayList<>();
List<BirdsDataBean> imageList = new ArrayList<>();
public ScheduleTaskAdapter(Context context, List<BirdsDataBean> imagesList) {
this.context = context;
this.imageList = imagesList;
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return imageList.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = layoutInflater.inflate(R.layout.routes_bird_row, parent, false);
holder.iv_birds = (ImageView) convertView.findViewById(R.id.iv_route_bird);
holder.frameLayout = (FrameLayout) convertView.findViewById(R.id.frame_route_bird);
holder.linearLayout = (LinearLayout) convertView.findViewById(R.id.route_bird_detail_view);
holder.imageView = (ImageView) convertView.findViewById(R.id.iv_hide);
holder.iv_video = (ImageView) convertView.findViewById(R.id.iv_seen);
holder.iv_sound = (ImageView) convertView.findViewById(R.id.iv_video);
holder.tv_short_descript = (TextView) convertView.findViewById(R.id.tv_bird_name);
holder.tv_category = (TextView) convertView.findViewById(R.id.tv_scientific_name);
holder.tv_long_description = (TextView) convertView.findViewById(R.id.tv_description);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Uri myUri = Uri.parse(birdsUrlList.get(position).getUrl());
Glide.with(getActivity()).load(myUri).placeholder(R.drawable.birds).into(holder.iv_birds);
holder.tv_short_descript.setText(birdsUrlList.get(position).getDescrip());
holder.tv_long_description.setText(birdsUrlList.get(position).getDescrip_larga());
holder.tv_category.setText(birdsUrlList.get(position).getNombre_cientifico());
final ViewHolder finalHolder = holder;
holder.frameLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finalHolder.linearLayout.setVisibility(View.VISIBLE);
finalHolder.iv_sound.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(birdsUrlList.get(position).getUrl_video())));
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
});
finalHolder.iv_video.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//hitBirdSeenService(birdsUrlList.get(position).getIdave());
// finalHolder.iv_video.setImageResource(R.drawable.eye_selected);
}
});
}
});
holder.imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finalHolder.linearLayout.setVisibility(View.GONE);
}
});
//Picasso.with(context).load(myUri).placeholder(R.drawable.image).into(holder.pic);
//malevich.load(helperTaskBeanList.get(position).getImage()).into(holder.pic);
return convertView;
}
}
static class ViewHolder {
ImageView iv_birds,imageView,iv_video,iv_sound;
FrameLayout frameLayout;
LinearLayout linearLayout;
TextView tv_short_descript,tv_category,tv_long_description;
}
}
And row layout for adapter
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/frame_route_bird"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:id="#+id/iv_route_bird"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="#string/name"
android:textSize="24sp"
android:textStyle="bold"
android:id="#+id/tv_bird_name"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textColor="#ffffff"
android:text="#string/bird_sub_category"
android:id="#+id/tv_scientific_name"/>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone"
android:background="#ffffff"
android:id="#+id/route_bird_detail_view"
android:paddingBottom="120dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/bird_hidden_text"
android:textSize="20sp"
android:padding="20dp"
android:id="#+id/tv_description"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/eye110"
android:id="#+id/iv_seen"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/right"
android:layout_marginTop="25dp"
android:layout_marginLeft="15dp"
android:id="#+id/iv_arrow"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/ear"
android:layout_marginLeft="15dp"
android:id="#+id/iv_video"/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="#D6D6D6"
android:layout_marginTop="20dp"
android:src="#drawable/up"
android:layout_gravity="center"
android:id="#+id/iv_hide"/>
</LinearLayout>
</LinearLayout>
Here are the screenshots of the problem
Comparing both images you can see that the hidden view appears in the space of the single row item and is scroll able completely in that space.
Better upshot were targeted at plus for android developers (Cristophe Beils):
"Your ListView must have its height set to match_parent or a fixed size, not wrap_content.
If you need to add another view fixed at the bottom of the ListView as a footer, you need to put both the ListView and the footer View in a vertical LinearLayout and set layout_height to 0dp and layout_weight to 1 on the ListView so that it takes the remaining vertical space."
Try fillViewPort=true on the list view.. But not sure what why yoi have a scroll view inside a list view.. Could be the issue too.
Try setting match_parent as the height of the listview
I suspect this will force the list view to have a defined height and fix your problem.

Adapting a layout using a Dialog Fragment

I'm trying to adapt a layout in a dialog fragment to show an imageview, a text view and two butttons, but I have problem adapting the layout in it.
I get this:
http://kitsord.com/imagestack/Screenshot_2014-05-22-11-35-22.png
And the output should look something like this:
http://kitsord.com/imagestack/looks.png
So I don't know why the text and the buttons don't show correctly.
The DialogFragment is this one:
public class LearnFragment extends DialogFragment {
ImageView imgC;
VideoView myVideoView;
View root ;
TextView textv ;
ImageButton next , atras;
Integer contador;
public static LearnFragment newInstance() {
LearnFragment f = new LearnFragment();
return f;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
contador = GridViewFragmet.positionarchivo; // this is a static variable from another class
if (getDialog() != null) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setBackgroundDrawableResource(android.R.color.transparent);
}
LayoutInflater inflaterr = getActivity().getLayoutInflater();
root = inflaterr.inflate(R.layout.aprender_fragment_display, null);
myVideoView = (VideoView)root.findViewById(R.id.videos_aprender);
imgC =(ImageView) root.findViewById(R.id.imagenes_aprender);
textv = (TextView) root.findViewById(R.id.text_aprender);
next = (ImageButton) root.findViewById(R.id.btnnext_aprender);
atras = (ImageButton) root.findViewById(R.id.btnatras_aprender);
myVideoView.setVisibility(View.GONE);
imgC.setVisibility(View.GONE);
textv.setVisibility(-1);
if(contador == 0) {
atras.setVisibility(-1);
} else if(contador > 0 && contador < LearnAdapter.imagenesAprender.size() - 1){
next.setVisibility(0);
atras.setVisibility(0);
} else if(contador == LearnAdapter.imagenesAprender.size() - 1) {
next.setVisibility(-1);
}
startIt(GridViewFragmet.nombrearchivo);
next.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
myVideoView.setVisibility(View.GONE);
imgC.setVisibility(View.GONE);
textv.setVisibility(-1);
if(contador + 1 < LearnAdapter.imagenesAprender.size()){
++contador;
startIt(LearnAdapter.imagenesAprender.get(contador));
atras.setVisibility(0);
if(contador == LearnAdapter.imagenesAprender.size() - 1){
next.setVisibility(-1);
}
}
}
});
atras.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
myVideoView.setVisibility(View.GONE);
imgC.setVisibility(View.GONE);
textv.setVisibility(-1);
if(contador - 1 >= 0){
--contador;
startIt(LearnAdapter.imagenesAprender.get(contador));
next.setVisibility(0);
if(contador == 0) {
atras.setVisibility(-1);
}
}
}
});
return root;
}
public void startIt(String archivo){
if(archivo.substring(archivo.lastIndexOf(".") + 1).equals(variablesGlobales.IMAGENES.obtenerinfo())) {
textv.setVisibility(0);
textv.setText(archivo.substring(archivo.lastIndexOf("/")+1, archivo.lastIndexOf(".")));
imgC.setVisibility(View.VISIBLE);
Bitmap bmp = BitmapFactory.decodeFile(archivo);
imgC.setImageBitmap(bmp);
} else {
textv.setVisibility(0);
textv.setText(archivo.substring(archivo.lastIndexOf("/")+1, archivo.lastIndexOf(".")));
myVideoView.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
}
});
myVideoView.setVisibility(View.VISIBLE);
myVideoView.setZOrderOnTop(true);
myVideoView.setVideoPath(archivo);
myVideoView.start();
}
}
#SuppressWarnings("deprecation")
#Override
public void onStart() {
super.onStart();
// change dialog width
if (getDialog() != null) {
int fullWidth = getDialog().getWindow().getAttributes().width;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
Display display = getActivity().getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
fullWidth = size.x;
} else {
Display display = getActivity().getWindowManager().getDefaultDisplay();
fullWidth = display.getWidth();
}
final int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources()
.getDisplayMetrics());
int w = fullWidth - padding;
int h = getDialog().getWindow().getAttributes().height;
getDialog().getWindow().setLayout(w, h);
}
}
}
The layout is this one:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/ll1"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_weight="1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal" >
<VideoView
android:id="#+id/videos_aprender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<ImageView
android:id="#+id/imagenes_aprender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/abc" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:id="#+id/text_aprender"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#0f9f9f"
android:gravity="center"
android:text="Large Text"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#fff"
android:textSize="25dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll3"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.8" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1" >
<ImageButton
android:id="#+id/btnatras_aprender"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#00FFFFFF"
android:src="#drawable/arrow_izq" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.9">
<ImageButton
android:id="#+id/btnnext_aprender"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#00FFFFFF"
android:src="#drawable/arrow_der" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I found my problem. The problem was at my class of Dialog Fragment.
The line that was giving me the error was this one:
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
That was what affected the whole dialog and moved the layout.

Categories

Resources