not getting the parent view elements in adapter - java

I have an adapter called PaymentMethodAdapter. I am trying to access it's parent view element, which is already there in xml.
ViewGroup parentView;
LinearLayout listView;
public View getView(int position, View convertView, ViewGroup parent) {
parentView = parent;
listView = (LinearLayout) parentView.findViewById(R.id.ben_pay_methods);
}
I am getting nullpointer exception error:
TRACE
01-20 13:22:47.075 6569-6569/com.example.android.mtesapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.android.mtesapp, PID: 6569
java.lang.NullPointerException
at com.example.android.mtesapp.PaymentMethodAdapter.getView(PaymentMethodAdapter.java:65)
at com.example.android.mtesapp.EditBeneficiaryActivity.show_receiving_methods(EditBeneficiaryActivity.java:315)
at com.example.android.mtesapp.EditBeneficiaryActivity$AsyncTaskGetBenPaymentMethods.onPostExecute(EditBeneficiaryActivity.java:299)
at com.example.android.mtesapp.EditBeneficiaryActivity$AsyncTaskGetBenPaymentMethods.onPostExecute(EditBeneficiaryActivity.java:283)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5872)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
at dalvik.system.NativeStart.main(Native Method)
How can I check the elements in the parent view exist or not?
EDIT
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
style="#style/panelLayout"
android:background="#color/white"
android:id="#+id/panel1"
>
<RelativeLayout
style="#style/panelFrame"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:layout_height="120dp"
android:layout_width="120dp"
android:id="#+id/ben_pic"
android:src="#drawable/bee"
android:background="#color/white"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="John Doe"
android:id="#+id/ben_first_name"
android:layout_alignTop="#+id/ben_pic"
android:layout_toRightOf="#+id/ben_pic"
android:layout_toEndOf="#+id/ben_pic"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:hint="First Name"
android:background="#drawable/blue_edit_text_holo_light"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="John Doe"
android:id="#+id/ben_last_name"
android:layout_below="#+id/ben_first_name"
android:layout_toRightOf="#+id/ben_pic"
android:layout_toEndOf="#+id/ben_pic"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:hint="Last Name"
android:background="#drawable/blue_edit_text_holo_light"
/>
<!-- <EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="someone#something.com"
android:id="#+id/ben_email"
android:hint="#string/email"
android:layout_below="#+id/ben_last_name"
android:layout_toRightOf="#+id/ben_pic"
android:layout_toEndOf="#+id/ben_pic"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:background="#drawable/blue_edit_text_holo_light"/>-->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="647-777-0000"
android:hint="#string/phone"
android:id="#+id/ben_phone1"
android:layout_below="#+id/ben_last_name"
android:layout_toRightOf="#+id/ben_pic"
android:layout_toEndOf="#+id/ben_pic"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:background="#drawable/blue_edit_text_holo_light"/>
<Button
style="#style/BtnDanger"
android:layout_width="wrap_content"
android:text="Delete"
android:id="#+id/delete_ben_btn"
android:layout_below="#+id/ben_phone1"
android:layout_toRightOf="#+id/ben_pic"
android:layout_toEndOf="#+id/ben_pic"
android:layout_height="40dp"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
style="#style/panelLayout"
android:id="#+id/panel2">
<TextView
style="#style/title_inside"
android:text="#string/address" />
<EditText
style="#style/Base.Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ben_address1"
android:text="123 Something Ave"
android:hint="#string/address"
android:background="#drawable/blue_edit_text_holo_light">
</EditText>
<!--<TextView
style="#style/LabelEdit"
android:text="#string/address" />-->
<EditText
style="#style/Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ben_address2"
android:text=""
android:hint="#string/address2"
android:background="#drawable/blue_edit_text_holo_light">
</EditText>
<EditText
style="#style/Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ben_city"
android:text="Toronto"
android:hint="#string/city"
android:background="#drawable/blue_edit_text_holo_light">
</EditText>
<EditText
style="#style/Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ben_province"
android:text="Ontario"
android:hint="#string/province"
android:background="#drawable/blue_edit_text_holo_light">
</EditText>
<TextView
style="#style/Widget.AppCompat.EditText"
android:id="#+id/ben_country"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/country"
android:background="#drawable/blue_edit_text_holo_light"/>
</LinearLayout>
<LinearLayout
style="#style/panelLayout"
android:id="#+id/panel3">
<TextView
style="#style/title_inside"
android:text="#string/receive_method" />
<LinearLayout
android:orientation="vertical"
android:id="#+id/ben_pay_methods"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layout1"
>
</LinearLayout>
<Button
style="#style/BtnInfo"
android:id="#+id/btn_add_new_method"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="add_new_method"
android:text="#string/add_new_method"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4"
android:layout_alignParentBottom="true">
<Button
style="#style/BtnPrimary"
android:id="#+id/btn_edit_beneficiary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/save"/>
</LinearLayout>
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>

As #Fouad Wahabi has already suggested in the comment, I found your layout XML is invalid.
There is no View with id of layout1. And also, though the LinearLayout is not a child View of RelativeLayout, it has an android:layout_below attibute. This can cause the error.
Try to remove the attribute like this:
<LinearLayout
android:orientation="vertical"
android:id="#+id/ben_pay_methods"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>

use convertView for inflating any view from item view of list
public View getView(int position, View convertView, ViewGroup parent) {
convertView = getActivity().getLayoutInflater().inflate(R.layout.your_xml, null);
listView = (LinearLayout) convertView.findViewById(R.id.ben_pay_methods);
}

Related

Listview not scrolling inside custom listview

I have a custom listview, inside of which there is another one. And the one that is nested will not scroll. Perhaps you need to register something in the parent setOnTouchListener? I don't have anything like that in getView.
image
my layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="#color/gray"
tools:context=".invoice.ListPruducts">
<ListView
android:id="#+id/lv1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:divider="#android:color/transparent"
android:dividerHeight="10.0sp"
android:paddingHorizontal="10dp"
android:paddingVertical="10dp"
android:stackFromBottom="true"
app:layout_constraintBottom_toTopOf="#+id/materialCardView2"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="10dp" />
<com.google.android.material.card.MaterialCardView
android:id="#+id/materialCardView2"
android:background="#color/zxing_transparent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/CustomCardViewStyle"
android:layout_marginTop="10dp"
app:cardElevation="10dp"
android:clickable="true"
android:focusable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="#+id/productName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:backgroundTint="#color/yellow"
android:enabled="false"
android:hint="Наименование"
android:textColor="#color/black"
android:textColorHint="#color/black"
android:textSize="24sp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/ll123"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/productName"
android:layout_marginHorizontal="5dp"
android:layout_marginTop="5dp"
android:baselineAligned="false"
android:orientation="horizontal">
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="#+id/search_barCode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:backgroundTint="#color/green"
android:ems="15"
android:focusable="true"
android:hint="Считайте ш/к"
android:textColorHint="#color/DefGray"
android:inputType="number"
android:maxLength="15"
android:textSize="18sp"
android:singleLine="true" />
<com.google.android.material.textfield.MaterialAutoCompleteTextView
android:id="#+id/coutOfProduct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.1"
android:backgroundTint="#color/green"
android:hint="Кол-во: "
android:inputType="numberSigned|numberDecimal"
android:maxLength="13"
android:singleLine="true"
android:textColor="#color/black"
android:textColorHint="#color/DefGray"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
`
my getView
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
GoodsCreate_SQL myItemFromList = getItem(position);
LayoutInflater inflater = LayoutInflater.from(mContext);
convertView = inflater.inflate(mResourse, parent, false);
TextView tvMark = convertView.findViewById(R.id.tvMark);
CheckBox cb = convertView.findViewById(R.id.checkBox2);
tvMark.setText(myItemFromList.Mark);
if (myItemFromList.myMark.equals("1")){
cb.setChecked(true);
}
return convertView;
}
Tried setOnTouchListener to write view.getParent().requestDisallowInterceptTouchEvent(true);

Programmatically check RadioButton

I have two radiobutton groups that need to be initialized when loading the screen, so I used this code:
mVisibilityPublic.setChecked(true);
But when I load the screen I get the following (first is the wrong behavior, second is the expected one):
I've tried with all these:
mVisibilityPublic.setSelected(true);
mVisibilityPublic.performClick();
mVisibilityPublic.setActivated(true);
mVisibilityPublic.invalidate();
mVisibilityPublic.requestLayout();
But I get the same result.
<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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="#dimen/form_vertical_spacing"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".createevent.CreateEventActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="#string/create_event_privacy"
android:textColor="#color/colorAccent"
android:textStyle="bold"
/>
<RadioGroup
android:id="#+id/create_visibility_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<RadioButton
android:id="#+id/createevent_visibility_public"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_public_event"/>
<RadioButton
android:id="#+id/createevent_visibility_private"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_private_event"/>
<RadioButton
android:id="#+id/createevent_visibility_ppv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv"/>
</RadioGroup>
<LinearLayout
android:id="#+id/ppv_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="#string/create_event_ppv_section"
android:textColor="#color/colorAccent"
android:textStyle="bold"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/ppv.currency.layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<com.myapp.ui.AutoCompleteCombo
android:id="#+id/ppv.currency"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/create_event_ppv_currency">
</com.myapp.ui.AutoCompleteCombo>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/ppv.price.layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_weight="1">
<android.support.design.widget.TextInputEditText
android:id="#+id/ppv.price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/create_event_ppv_price"
android:imeOptions="actionDone"
android:inputType="numberDecimal"
android:maxLines="1"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<RadioGroup
android:id="#+id/ppv_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<RadioButton
android:id="#+id/ppv_all"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv_allcountries"/>
<RadioButton
android:id="#+id/ppv_allexcept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv_except"/>
<RadioButton
android:id="#+id/ppv_only"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/create_event_ppv_some"/>
</RadioGroup>
<com.myapp.countries.CountriesMultiCombo
android:id="#+id/create.ppv.countrylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
</LinearLayout>
<View
android:id="#+id/separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/general_info"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginLeft="-32dp"
android:layout_marginRight="-32dp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:background="#color/colorDivider"
/>
<LinearLayout
android:id="#+id/geoblock_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="visible">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="#string/geo_blocking_settings_title"
android:textColor="#color/colorAccent"
android:textStyle="bold"
/>
<RadioGroup
android:id="#+id/geo_radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingTop="16dp">
<RadioButton
android:id="#+id/geo_none"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/geo_none"/>
<RadioButton
android:id="#+id/geo_blockonly"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/geo_block_only"/>
<RadioButton
android:id="#+id/geo_blockexcept"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/geo_block_all_except"/>
</RadioGroup>
<com.myapp.createevent.countries.CountriesMultiCombo
android:id="#+id/create.geo.countrylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
/>
</LinearLayout> <Button
android:id="#+id/test_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CLICK ME"/>
</LinearLayout>
</ScrollView>
Note that if I select the option manually (like I did with the second example in the image) I get the proper result. Its only if I do it programmatically that its missing the inner circle.
public class TestFragment extends Fragment {
private Unbinder mUnbinder;
#BindView(R.id.createevent_visibility_public)
RadioButton mVisibilityPublic;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View inflate = inflater.inflate(R.layout.fragment_advanced_opts, container, false);
mUnbinder = ButterKnife.bind(this, inflate);
return inflate;
}
public static TestFragment newInstance(int tvId, int eventId) {
TestFragment testFragment = new TestFragment();
Bundle args = new Bundle();
args.putInt(TV_ARGUMENT, tvId);
args.putInt(EVENTID_ARGUMENT, eventId);
testFragment.setArguments(args);
return testFragment;
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mVisibilityPublic.setChecked(true);
}
}

How to access views from the programatically inflated layouts?

I have an activity in which I have inflated another layout. OnClick of next destination I am getting inflated a new layout. Now I want to remove the inflated layout. So I want to access the linear layout of remove from inside inflated layout. How can I access this??
Layout looks like this :
I have achieved to inflate layout and remove the first destination from parent which is a part of parent layout. Now I want to do same with inflated destination layout. onClick of remove the inflated layout should get removed.
Next_destination layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_weight="1.00"
android:background="#android:color/white"
android:id="#+id/LinearAddedDestination">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DESTINATION"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:orientation="horizontal"
android:background="#drawable/shape"
android:gravity="right"
android:layout_gravity="center|right"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="80dp"
android:id="#+id/remove">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_clear_black_18dp"
android:layout_marginLeft="05dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="REMOVE"
android:layout_gravity="center"
android:layout_marginLeft="05dp"
android:textSize="14sp"
android:layout_marginRight="15dp" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="08dp"
android:background="#drawable/line2"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_place_black_48dp"
android:layout_marginTop="05dp"
android:layout_gravity="center" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="#drawable/ic_chevron_right_black_24dp"
android:layout_marginEnd="10dp"
android:text="#string/Loc"
android:layout_gravity="center"
android:layout_marginTop="05dp"
android:textAppearance="#android:style/TextAppearance.Medium"
android:cursorVisible="false"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Street/Building/Place"
android:layout_marginStart="48dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginEnd="10dp"
android:hint="#string/LocationDetails"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginStart="48dp"
android:hint="#string/HouseDetails" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_person_black_48dp"
android:layout_marginTop="05dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:text="#string/additionalContact"
android:textAppearance="?android:attr/textAppearanceMedium"
android:drawableEnd="#drawable/ic_expand_more_black_24dp"
android:layout_marginTop="08dp"
android:layout_marginStart="05dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginEnd="50dp"
android:layout_gravity="center"
android:visibility="gone"
android:layout_marginTop="20dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Name"
android:layout_gravity="center"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Phone"
android:layout_gravity="center"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/or"
android:layout_gravity="center"
android:layout_marginTop="20dp" />
<LinearLayout
android:layout_width="220dp"
android:layout_height="40dp"
android:background="#drawable/shape"
android:layout_gravity="center_horizontal">
<ImageButton
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#drawable/phone2"
android:layout_gravity="center"
android:layout_marginStart="30dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="#string/addFromContacts"
android:layout_gravity="center"
android:layout_marginStart="20dp" />
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginLeft="48dp"
android:hint="#string/contact1"
android:layout_marginTop="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:focusable="true"
android:focusableInTouchMode="true">
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginStart="20dp"
android:background="#drawable/ic_description_black_48dp"
android:layout_marginTop="10dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginEnd="10dp"
android:hint="Instruction"
android:layout_gravity="center"
android:layout_marginLeft="10dp" />
</LinearLayout>
</LinearLayout>
Activity from on which the layout is inflated.
View newDestination;
ViewGroup parent;
nextDestination.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
removeDestination.setVisibility(View.VISIBLE);
newDestination = getLayoutInflater().inflate(
R.layout.next_destination_layout, addDestination, true);
}
});
removeDestination.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
parent = (ViewGroup)destination.getParent();
parent.removeView(destination);
}
});
How to achieve this?? Please help...
{ ll.removeView(view)// to remove particular view
ll.removeViewAt(position);// to remove view from particular position
}

Android - Snackbar Cover my View

Why Snackbar cover my view
here is my xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fullview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/dark_gray"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/reload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_centerInParent="true"
android:text="#string/reload"
android:visibility="visible" />
<ProgressBar
android:id="#+id/progressbar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:visibility="gone" />
<android.support.v7.widget.RecyclerView
android:id="#+id/complist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fadeScrollbars="false" />
</RelativeLayout>
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="5dp"
android:orientation="horizontal">
<Button
android:id="#+id/send"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#color/blue"
android:text="#string/send"
android:textColor="#android:color/white" />
<Button
android:id="#+id/cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:background="#color/green"
android:text="#string/cancel"
android:textColor="#android:color/white" />
</LinearLayout>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
java code used to show snake bar
private CoordinatorLayout _CoordinatorLayout;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.compition, null);
_CoordinatorLayout = (CoordinatorLayout) v.findViewById(R.id.fullview);
}
Snackbar.make(_CoordinatorLayout , message , Snackbar.LENGTH_LONG).show();
here is screen shot
what I miss ??
The documentation here says:
Snackbars appear above all other elements on screen and only one can
be displayed at a time.
So, Snackbar will cover your view, just like a Toast.

Expand ListItem on click to a new view

I have a listview with some texts in it like this
and I want to expand each item to like this
I have seen this answer(How can I make a cell in a ListView in Android expand and contract vertically when it's touched?), here it doesn't changes to a new view, but just changes the height.
UPDATE:list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:clickable="true"
android:background="#drawable/list_selected">
<RelativeLayout
android:id="#+id/relaboveline1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/sidebar"
android:layout_width="15dp"
android:layout_height="match_parent"
android:background="#4ED6CA" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:weightSum="100"
android:layout_toRightOf="#+id/sidebar"
android:layout_toEndOf="#+id/sidebar">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20">
<RelativeLayout
android:id="#+id/cal"
android:layout_width="60dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="22"
android:textColor="#FF8801"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:textSize="35sp"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/month"
android:textColor="#FF8801"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/date"
android:textSize="20sp"
android:text="MAY" />
<TextView
android:id="#+id/year"
android:textColor="#FF8801"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/month"
android:textSize="20sp"
android:text="2015" />
</RelativeLayout>
<View
android:id="#+id/divider"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/cal"
android:layout_toEndOf="#+id/cal"
android:background="#DADADA" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="60">
<RelativeLayout
android:id="#+id/content"
android:layout_width="200dp"
android:paddingTop="5dp"
android:paddingLeft="8dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold"
android:text="High School Graduation" />
<TextView
android:id="#+id/contentdesc"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:text="#string/dummy" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="20">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:text="5B"
android:id="#+id/classDiv" />
<RelativeLayout
android:layout_below="#+id/classDiv"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerInParent="true"
android:src="#drawable/star_yellow" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<View
android:id="#+id/line2"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_below="#+id/relaboveline1"
android:background="#DADADA" />
You can use ExpandableListView:
You define a custom layout for the child (the details when you click on the row)
You define an public class ExpandableAdapter extends BaseExpandableListAdapter
Override the method
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
....
}
where you implement your detail layout (child layout).
Override the method
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
...
}
where you implement the layout like the ListView.
Set the custom adapter in your ExpandableListView instance
If you want to have more info give a look at my post here http://www.survivingwithandroid.com/2013/01/android-expandablelistview-baseexpandablelistadapter.html
Have you tried ExpandableListView with only one child view for each group view? then you can expand and collapse rows as you want.

Categories

Resources