I had an ExpandableListView with a CheckedTextView as grouprow View. But I needed to reduce spacing between groups so I've put it inside a LinearLayout. The List does not expand since then, just no reaction on clicks. Any ideas? Code goes below
grouprow.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/holder"
android:clickable="true"
android:orientation="vertical">
<CheckedTextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-13dp"
android:layout_marginBottom="-13dp"
android:text="#string/hello_world"
android:paddingLeft="20dp"
android:textColor="#FFFFFF"
android:textSize="60sp"
android:includeFontPadding="false"
android:textStyle="bold" />
</LinearLayout>
getting the group view:
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = minflater.inflate(R.layout.grouprow, null);
}
LinearLayout holder = (LinearLayout) convertView;
CheckedTextView txtGr = (CheckedTextView) holder.findViewById(R.id.textView1);
txtGr.setText(groupItem.get(groupPosition));
txtGr.setChecked(isExpanded);
font = Typeface.createFromAsset(activity.getAssets(),
"uww.otf");
txtGr.setTypeface(font);
return convertView;
}
solved the problem by setting both the LinearLayout and the CheckedTextView to non-clickable
Related
I have an ExpandableListView that I'm populating with items. I'd like to have the header (here, "meat") be wider than the list items.
However, ExpandableListView doesn't seem to respect margins/padding defined in XML, and also fails to respect programatically-set padding for the items. It does modify the parent ("meat") but the same code doesn't work for the items.
How can I do this?
Here's the relevant part of my custom adapter:
#Override
public View getGroupView(int position, boolean isExpanded, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.list_category, null);
}
view.setPadding(10, 0, 10, 0); //RESPECTED
initializeGroupComponents(view, getGroup(position));
return view;
}
#Override
public View getChildView(int position, int expandedPosition, boolean isLastChild, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.list_ingredient, parent, false);
}
view.setPadding(10, 2, 10, 2); //DOES NOT WORK
initializeChildComponents(view, getChild(position, expandedPosition));
return view;
}
The relevant portions of my XML:
The group:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_categoryContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:orientation="vertical">
The item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/row"
android:layout_width="match_parent"
android:layout_height="62dp"
android:layout_marginBottom="1dp"
android:layout_marginEnd="6dp"
android:layout_marginStart="6dp"
android:background="#android:color/white"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="10dp">
Take one extra layout for header and add margin
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_categoryContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp">
//other content
</LinearLayout>
</LinearLayout>
I have a layout for my gird item which contains a linear layout and in that a textView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="120dp"
android:minHeight="120dp"
android:background="#drawable/bg_all_white_rounded_gray"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/ui_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="#dimen/margin_social_logo"
android:gravity="center"
android:text="Family Friends"
android:textColor="#color/colorPrimaryDark"
android:textSize="#dimen/font_text"
android:visibility="visible" />
</LinearLayout>`
When i call
inflater.inflate(R.layout.main_grid_row, parent, false); from adapter it returns view of type
android.support.design.internal.NavigationMenuView
instead of a linear layout.
#Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
View rowView = convertView;
ViewHolderCategories holder = null;
if (convertView == null) {
rowView = mInflater.inflate(R.layout.main_grid_row, parent, false);
holder = new ViewHolderCategories(mContext, rowView);
rowView.setTag(holder);
} else {
holder = (ViewHolderCategories) rowView.getTag();
}
MainCategory data = mAllData.get(position);
holder.updateView(data.getCategoryName());
return rowView;
}
I am not able to figure why its returning some other view instead of a liner layout
Try this:
rowView = LayoutInflater.from(parent.getContext()).inflate(R.layout.main_grid_row, null);
This is my Activity layout file in which i have added the grid view.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#color/colorAppTheme">
<GridView
android:id="#+id/grid_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:columnWidth="90dp"
android:horizontalSpacing="10dp"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" /></RelativeLayout>
just removed the android:gravity="center" form GridView and its working fine.
Don't have any idea how its related but i thought to post the answer.
I am trying to indent listView row by certain factor. For this, I used view.layout() and view.setX() method but they don't work or result in forceclose. Is there a way to achieve this result. Here is my code:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View newRowView = convertView;
ViewHolder viewHolder;
if(newRowView == null)
{
LayoutInflater inflator = (LayoutInflater) con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
newRowView = inflator.inflate(R.layout.list_view_images, parent,false);
//newRowView.layout(100*(position/list.size()), 0, 0, 0); // not working
newRowView.setX(100*(position/list.size())); // causing force close
viewHolder = new ViewHolder();
viewHolder.appIcon = (ImageView) newRowView.findViewById(R.id.imageView1);
viewHolder.appName = (TextView) newRowView.findViewById(R.id.textView1);
viewHolder.appName.setText(names.get(position));
newRowView.setTag(viewHolder);
}
list_view_images.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="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
I am trying to indent the list in semi circular fashion.
What can I do achieve required results?
Regards
Update your getView() method as follows:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View newRowView = convertView;
ViewHolder viewHolder;
if (newRowView == null) {
LayoutInflater inflator = (LayoutInflater) con.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
newRowView = inflator.inflate(R.layout.list_view_images, parent, false);
viewHolder = new ViewHolder();
viewHolder.innerContainer = (LinearLayout) newRowView.findViewById(R.id.innerContainer);
viewHolder.appIcon = (ImageView) newRowView.findViewById(R.id.imageView1);
viewHolder.appName = (TextView) newRowView.findViewById(R.id.textView1);
viewHolder.appName.setText(list.get(position));
newRowView.setTag(viewHolder);
}
else {
viewHolder = (ViewHolder) newRowView.getTag();
}
float shiftRight = 100 * ((position * 1.0f) / list.size());
viewHolder.innerContainer.setPadding((int) shiftRight, 0, 0, 0);
//...
//...
return newRowView;
}
Update your XML layout as follows:
<?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="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/innerContainer"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
Update your ViewHolder to contain another field as following:
public LinearLayout innerContainer;
Explanation: Basically, we put your original XML layout inside a LinearLayout that acts as an outer container. The we assign padding to the innerContainer (original layout) with respect to the outer layout
I want to display multiple imageview and text view on every row of listview and number of row is not fix (number of rows integer can be fetched from server)
How can i add horizontal scroll view in every row.
i am going to use for loop for number of imageview in getView method is it right way to do that.
My question is how can i inflate horizontal scroll with numbers image views in row in getview method
public View getView(final int position, View convertView,
ViewGroup parent)
{
final ViewHolder viewHolder;
viewHolder = new ViewHolder();
// View vi = convertView;
//if (vi == null)
//{
int Numberofimageview=2;
for(int i=0;i<Numberofimageview;i++)
{
// assume i want to display 2 imageview in every row
LayoutInflater inflater = (LayoutInflater) con
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.my_row_layout, parent,
false);
viewHolder.title = (TextView) convertView.findViewById(R.id.title);
Log.d("myapp", "position" + position);
convertView.setTag(viewHolder);
// }
// else
// {
// viewHolder=(ViewHolder)convertView.getTag();
// }
viewHolder.title.setText(data.get(position));
}
return convertView;
}
This is xml for row
RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/wagon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/wagon" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/wagon"
android:layout_centerVertical="true"
android:layout_marginLeft="16dp"
android:src="#drawable/video" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_marginLeft="33dp"
android:layout_toRightOf="#+id/imageView1"
android:text="title of file" />
<TextView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/title"
android:layout_alignRight="#+id/title"
android:layout_marginBottom="18dp"
android:text="type of file" />
Try to include your relativeLayout into a HorizontalScrollView
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout>[...]</RelativeLayout>
</HorizontalScrollView>
Create a custom listview. Create a xml file. within the main linear layout of the xml file put imageview and textview. Make sure the orientation of the linear layout is horizontal.. Make use of that xml file in getview methood
This is what I have, I Expandable listview. Each Group item is a Checkbox witha Textview next to it.
I want that checkbox to be toggled checked/unchecked if the group is expanded or not expanded.
Also vica versa, so if the checkbox is checked, the list should be expanded etc.
Any ideas?
this is my group_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<CheckBox
android:id="#+id/check_channel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:focusable="false"
android:layout_gravity="left"
android:checked="false" />
<TextView
android:textSize="20sp"
android:textIsSelectable="false"
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="55dp"/>
</RelativeLayout>
It looks pretty, just need it to check and uncheck .
Ah ok, this is how i Did it
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,ViewGroup parent) {
View v;
if (convertView == null) {
v = newGroupView(isExpanded, parent);
} else {
v = convertView;
}
if ( isExpanded ) {
((CheckBox) v.findViewById(R.id.check_channel)).setChecked(true);
} else {
((CheckBox) v.findViewById(R.id.check_channel)).setChecked(false);
}
bindGroupView(groupPosition, isExpanded, v, parent);
return v;
}