Good day!
I have tried a lot of other posts on stackoverflow but it didn't work for me,
maybe its because I'm new to Android Development.
My problem is as follow:
XML Layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:layout_width="match_parent"
android:layout_height="89dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/txtDetails"
android:layout_gravity="center_horizontal|top"
android:padding="5dp" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="369dp"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
Preview in Android Studio:
inside the onCreateView:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { }
Binding the listview:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_item_detail, container, false);
List<Events> list = Events.getEvents();
int max = list.size();
String[] Values = new String[max];
for (int i = 0; i < max; i++) {
Events e = list.get(i);
Values[i] = e.getNaam();
}
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
rootView.getContext(),
android.R.layout.simple_list_item_1, Values);
listView.setAdapter(arrayAdapter);
return rootview;
}
Another point is i can't click a list item wich is strange !
Any ideas or tips?
what do i wrong?
Kind Regards,
Stefan
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/txtDetails"
android:layout_gravity="center_horizontal|top"
android:padding="5dp" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom" />
</FrameLayout>
Try something like the following.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/txtDetails"
android:layout_gravity="center_horizontal|top"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="10dp"
android:paddingBottom="10dp" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</FrameLayout>
<LinearLayout>
<ScrollView>
<ListView ...>
</listView>
</ScrollView>
</LinearLayout>
You need to add a LinearLayout around the scrollview, that way the scrollview knows inside what it should scroll. If this doesn't work, replace the ListView with another LinearLayout and add your items to the LinearLayout. I'm not sure if a View is capable of scrolling at all. Try first option first, otherwise try the latter. I know the latter will work for sure since I used the exact same design myself in an app I'm developing.
As already mentioned in the comment, you have to add a ScrollView around your ListView, e.g.:
<ScrollView>
<ListView ....>
</ListView>
</ScrollView>
Related
I want to display a recycler view inside the ExpandableListView header item.But I am getting an issue my header is not clickable when I put a recycler view in it.
Here is my code:-
header.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"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1"
android:padding="8dp"
android:background="#color/grey">
<TextView
android:id="#+id/lblListHeader"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="5dp"
android:textSize="15dp"
android:layout_weight=".25"
android:text="#"
android:textColor="#color/ModeltitleColor" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".65"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/ivRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
/>
</LinearLayout>
<ImageView
android:id="#+id/iv_group_indicator"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_weight=".10"
android:src="#drawable/ic_arrow_drop_down_black_24dp" />
</LinearLayout>
</LinearLayout>
here I am setting the group:-
#Override
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
if (view == null) {
view = LayoutInflater.from(context).inflate(R.layout.zonal_list_group, viewGroup, false);
}
TextView textView = view.findViewById(R.id.lblListHeader);
RecyclerView recyclerView=view.findViewById(R.id.ivRecyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false));
ZoneNameAdapter zoneNameAdapter =new ZoneNameAdapter(zonalSnapShotResponse.keyFigureDataGroups.get(i).zones,context);
recyclerView.setAdapter(zoneNameAdapter);
ImageView imageView = view.findViewById(R.id.iv_group_indicator);
textView.setText(zonalSnapShotResponse.keyFigureDataGroups.get(i).dataGroup);
imageView.setImageResource(R.drawable.ic_arrow_drop_down_black_24dp);
if (b) {
imageView.setRotation(180f);
} else {
imageView.setRotation(0f);
}
return view;
}
getChildItemCount does not get called when I put recycler view in the header.
I have tried multiple solutions but noting worked for me.Please help
i would like to add to a LinearLayout some imageViews dynamically in my app.
My following code doesn't show errors and prints what it is supposed to on logcat each time an ImageView is added from java code.
My problem is that when i run the app the images don't appear on screen....any idea where i am doing wrong ?
thanks a lot.
public class MesListesFragment extends Fragment {
private RecyclerView mes_listes_recyclerView;
private ArrayList<ListItem> liste_items;
private LinearLayout list_card_categories;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.mes_listes_fragment, container, false);
View view2 = inflater.inflate(R.layout.list_item, container, false);
mes_listes_recyclerView = view.findViewById(R.id.mes_listes_recyclerView);
list_card_categories = view2.findViewById(R.id.list_card_recyclerView);
liste_items = new ArrayList<>();
for (int i = 0; i < 10; i ++){
liste_items.add(new ListItem("Liste des ploucs", "18 Août 198" + i));
}
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
mes_listes_recyclerView.setLayoutManager(linearLayoutManager);
mes_listes_recyclerView.setAdapter(new ListViewAdapter(getContext(), liste_items));
for (int i = 0; i < 8; i++){
ImageView image = new ImageView(getContext());
image.setImageResource(R.drawable.user);
list_card_categories.addView(image);
Log.d("view created", "...");
}
return view;
}
}
Here is the xml, the file's called list_item.xml :
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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="150dp"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="10dp"
app:cardCornerRadius="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/list_card_first_container"
android:layout_width="match_parent"
android:layout_height="100dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/list_card_textView_nom_liste"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nom de la liste"></TextView>
<TextView
android:id="#+id/list_card_textView_date_liste"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date liste"></TextView>
</LinearLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50">
<LinearLayout
android:id="#+id/list_card_recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:gravity="center"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/list_card_second_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/list_card_first_container"
android:gravity="center"
android:orientation="horizontal"
android:paddingVertical="5dp">
<Button
android:id="#+id/list_card_button_editer"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginEnd="20dp"
android:background="#color/bleu_fb"
android:text="#string/editer"></Button>
<Button
android:id="#+id/list_card_button_supprimer"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:background="#android:color/holo_red_light"
android:text="#string/supprimer"></Button>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
I am adding views to my adapter dynamically and when the views exceeds the screen boundaries I am unable to see the full views.
I have tried android:isScrollContainer="true" and android:scrollbars="vertical" without any luck.
public void onAddField(View v) {
final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.field, null);
spin = rowView.findViewById(R.id.type_spinner2);
weightLayout = rowView.findViewById(R.id.myLayout);
getdata();
spin.setAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_dropdown_item, arrayList2));
parentLinearLayout.addView(rowView, parentLinearLayout.getChildCount() - 1);
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#E5E5E5"
android:orientation="vertical"
android:scrollbars="vertical"
android:isScrollContainer="true">
Try to use this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="50dp"
android:text="TextView" />
</LinearLayout>
</ScrollView>
</LinearLayout>
This way your ScrollView will expand with your LinerLayout.
I have a hidden layout.
add_event_price.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/add_event_price_layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<EditText android:id="#+id/add_event_wording"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:hint="#string/event_wording_hint" />
<EditText android:id="#+id/add_event_price"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="#string/event_price_hint" />
<ImageButton android:id="#+id/add_event_cross"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="#drawable/cross"
android:background="#null"
android:layout_gravity="center_vertical"
android:contentDescription="#string/delete" />
</LinearLayout>
When clicking on a button in the main layout, the hidden layout appears.
<ScrollView 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#color/app_background_color">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="#+id/add_event_dynamic"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
<Button android:id="#+id/add_event_add_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:text="#string/add_event_add_field" />
</LinearLayout>
</ScrollView>
add_event_add_field.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
LinearLayout priceLayout = (LinearLayout) rootView.findViewById(R.id.add_event_price_layout);
LinearLayout dynamicLayout = (LinearLayout) rootView.findViewById(R.id.add_event_dynamic);
View hidden = inflater.inflate(R.layout.add_event_price, priceLayout, false);
dynamicLayout.addView(hidden);
}
});
Adding the hidden layout dynamically works but I don't know how to retrieve the values of the EditText in the hidden layout, and delete a view when clicking on the corresponding add_event_cross ImageButton.
First, you can call findViewById on dynamicLayout:
EditText et = (EditText) dynamicLayout.findViewById(R.id.add_event_wording);
Second, I suggest not to show/hide layout by adding view. Just put the dynamicLayout inside your main layout and use something like:
dynamicLayout.setVisibility(LinearLayout.GONE); //makes the layout hidden
I have not tested the code but you can build upon it.
Im new to Android and I'm trying to add a TableRow, which I already made with xml, to a TableLayout programmatically. I'm getting Force Closes, most are NullPointerExcpetions.
Here's my java class
public class DayFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.subjects_list, container, false);
TableLayout tl = (TableLayout) view.findViewById(R.id.tl);
TableRow tr = (TableRow) view.findViewById(R.id.tr_row);
tl.addView(tr); //not working, obviously im missing something
//xml parsing stuff
return view;
}
}
This is my layout with the TableLayout:
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="5dp" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical" >
<TableLayout
android:id="#+id/tl"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<include
android:id="#+id/header"
layout="#layout/table_header" />
<include android:id="#+id/h_divider"
layout="#layout/horizontal_divider"/>
</TableLayout>
</ScrollView>
</HorizontalScrollView>
And the TableRow:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tr_row"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tv_hour"
android:layout_weight="1"
android:gravity="center"
android:padding="8dp"
android:textSize="15sp"
android:textStyle="bold" />
<View
android:layout_weight="1"
android:background="#drawable/vertical_cell_divider" />
<TextView
android:id="#+id/tv_subject"
android:layout_weight="1"
android:gravity="left"
android:padding="8dp"
android:textSize="18sp" />
<View
android:layout_weight="1"
android:background="#drawable/vertical_cell_divider" />
<TextView
android:id="#+id/tv_start"
android:layout_weight="1"
android:gravity="left"
android:padding="8dp"
android:textSize="18sp" />
<TextView
android:id="#+id/tv_bar"
android:layout_weight="1"
android:gravity="left"
android:textSize="18sp" />
<TextView
android:id="#+id/tv_end"
android:layout_weight="1"
android:gravity="left"
android:padding="8dp"
android:textSize="18sp" />
</TableRow>
I tried lots of different ways to achieve it but still nothing.
Replace code:
TableRow tr = (TableRow) view.findViewById(R.id.tr_row);
tl.addView(tr); //not working, obviously im missing something
with
View tr = inflater.inflate(R.layout.table_row_layout, null,false);
tl.addView(tr); //not working, obviously im missing something