Android Recyclerview GridLayoutManager when row given layout doesn't wrap its content - java

I'm trying to make a color picker application by using Recyclerview and GridlayoutManager for listing the colors. I am using ImageButton for presenting the colors. There are two recyclerviews, first one displays main colors that i made up and the second one displays the tint and shadow of the selected color from the first one. My code is ugly but this is for experimenting so right now i just want to make the second recyclerview with gridlayoutmanager be in two rows and 4 columns. I could make it with the code below but it only shows the first 4 colors and for the other ones i have to scroll down the view.
MainActivity:
package tr.com.beyes.colorpicker;
import android.content.res.Resources;
import android.graphics.Color;
import android.support.v4.content.res.TypedArrayUtils;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources r=getResources();
int[] fontColors = r.getIntArray(R.array.fontcolors);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.fontColorView);
GridLayoutManager gridLayoutManager = new GridLayoutManager(this,11, GridLayoutManager.VERTICAL, true);
recyclerView.setLayoutManager(gridLayoutManager);
RecyclerView recyclerView2 = (RecyclerView) findViewById(R.id.fontColorViewSub);
GridLayoutManager gridLayoutManager2 = new GridLayoutManager(this,4);
recyclerView2.setLayoutManager(gridLayoutManager2);
int[] tint = new int[8];
tint[0]=(Color.rgb(0,0,0));
int red = Color.red(fontColors[0]);
int green = Color.green(fontColors[0]);
int blue = Color.blue(fontColors[0]);
for(int i=1; i<7;i++){
red = (int) (red + (255-red) * 0.25);
green = (int) (green + (255-green) * 0.25);
blue = (int) (blue + (255-blue) * 0.25);
tint[i]=(Color.rgb(red,green,blue));
}
tint[7]=(Color.rgb(255,255,255));
ColorPickerAdapter colorPickerAdapter2 = new ColorPickerAdapter(tint,this, null);
recyclerView2.setAdapter(colorPickerAdapter2);
ColorPickerAdapter colorPickerAdapter = new ColorPickerAdapter(fontColors,this,colorPickerAdapter2);
recyclerView.setAdapter(colorPickerAdapter);
}
}
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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="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"
tools:context="tr.com.beyes.colorpicker.MainActivity"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fontColorView"
>
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fontColorViewSub"
android:layout_marginTop="20dp"
>
</android.support.v7.widget.RecyclerView>
</LinearLayout>
colorbox.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="24dp"
android:id="#+id/fontColorBox"
android:clickable="true"
/>
</LinearLayout>

1. Use setHasFixedSize(true) to recyclerView and recyclerView2
2. Update gridLayoutManager2 parameter as below:
GridLayoutManager gridLayoutManager2 = new GridLayoutManager(this, 4, GridLayoutManager.VERTICAL, true);
3. Use NestedScrollView as a container of your LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="tr.com.beyes.colorpicker.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fontColorView" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fontColorViewSub"
android:layout_marginTop="20dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Hope this will work~

Related

Cannot get id of BottomNavigationView

I'm setting up a bottom navigation for my app. I want to set/customize the actions for the menus but I'm facing an issue in the code. It can not find the id 'bottomNavView_bar' of the bottomnavigationview. I'm getting the error "Can't resolve symbol 'bottomNavView_bar'"
Here is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!--parent relative layout-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/parent_relative_layout">
<!--top bar layout-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/relLayoutTopbar">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tabs">
</com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.AppBarLayout>
</RelativeLayout>
<!--middle layout-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/relLayoutMiddle"
android:layout_below="#id/relLayoutTopbar"
android:background="#color/mainbackgroud">
<!--view pager-->
<androidx.viewpager.widget.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/homecontainer">
</androidx.viewpager.widget.ViewPager>
</RelativeLayout>
<!--bottom bar layout-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/relLayoutBottombar"
android:layout_alignParentBottom="true">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bottomNavView_bar"
app:itemBackground="#color/bgBottomNavigation"
android:foreground="?attr/selectableItemBackground"
app:itemIconTint="#android:color/white"
app:itemTextColor="#android:color/white"
app:menu="#menu/bottom_navigation_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Here's the menu file bottom_navigation_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_shop"
android:icon="#drawable/news"
android:title="#string/title_home" />
<item
android:id="#+id/navigation_games"
android:icon="#drawable/hockeystick"
android:title="#string/title_games" />
<item
android:id="#+id/navigation_stats"
android:icon="#drawable/graphic"
android:title="#string/title_stats" />
<item
android:id="#+id/navigation_settings"
android:icon="#drawable/settings"
android:title="#string/title_settings" />
</menu>
here is part of my MainActivity.java
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import android.os.Bundle;
import android.view.MenuItem;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setElevation(0);
mSectionsPagerAdapter = new
SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = findViewById(R.id.homecontainer);
setupViewPager(mViewPager);
TabLayout tabLayout = findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
tabLayout.getTabAt(0).setIcon(R.drawable.ic_rss_feed);
tabLayout.getTabAt(1).setIcon(R.drawable.ic_alarm);
//bottom navigation bar
BottomNavigationView navigation =
(BottomNavigationView)findViewById(R.id.bottomNavView_bar); //trying to get the view id here
BottomNavigationViewHelper.disableShiftMode(navigation);
}
Select tools>-android>-SDK manager
and download the SDK build tools, SDK platform and Google API's( the Google API stores packages such as "import android.view.Menu" etc.) for the target SDK version of your project(20 as shown in your screenshot). if you are not sure which items you have to download, you can select all of them. (will take more time to download of course).
Restart the IDE

ListView not Showing any items

I am trying to display array items in ListView using ArrayAdapter. it's not showing any items in ListView and not showing any error's below is my java class and xml.
package church.llagc.com;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class listView extends AppCompatActivity {
ArrayAdapter<String> adapter;
String[] alphabitlist = {"A","Aa","I","EE","U","Uu","E","EI","O","Oo","Ka","Ga","Cha","Ja","Tha","Da","Na","Pa","Ba",
"Bha","Ma","Ya","Ra","La","Va","Ssa","Sha","Sa","Ha"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view);
adapter= new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,alphabitlist);
ListView alpabits = (ListView) findViewById(R.id.alphabitorder);
alpabits.setAdapter(adapter);
}
}
containt_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="church.llagc.com.MainActivity"
tools:showIn="#layout/app_bar_main">
<include layout="#layout/activity_list_view"/>
</android.support.constraint.ConstraintLayout>
and my activity_list_view.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:orientation="horizontal"
tools:context="church.llagc.com.listView">
<ListView
android:background="#drawable/alphabit_bg"
android:id="#+id/alphabitorder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:scrollbars="none"/>
<ListView
android:id="#+id/itemcontent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"/>
</LinearLayout>
Please comment if you have any doubts.
Do not use android.R.layout.simple_list_item_1 and create you own layout file. This android.R.layout.simple_list_item_1 layout file has a simple text view but the text color is something related to white that's why you cant see it. Now you have to create a new layout file which contain only text view and set text color and pass it to your adapter
Try this.
<ListView
android:background="#drawable/alphabit_bg"
android:id="#+id/alphabitorder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:scrollbars="none"/>
<ListView
android:id="#+id/itemcontent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="8"/>
</LinearLayout>

GridView Layout RowSpan Issue

i'm building an android app using Android Studio and I want to display my items(images-using imageViews) in rows(4 in each one) but when I add more than 4 items, instead of the next item been taken to the next row, it just doesn't show up at all. What am I missing? I tried tweaking multiple things but none of it worked. Keep in mind that i'm new to android app development so i'm not sure if my layout choices are "optimal".Below you will find my xml file that handles all of the layout parts:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="20dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="#+id/toolbar">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="70dp"
android:text="Cards List"
android:textColor="#android:color/holo_blue_light"
android:textSize="40sp" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"></android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
<android.support.v7.widget.LinearLayoutCompat
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:verticalSpacing="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<GridView
android:id="#+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="4"
android:paddingBottom="500dp"
android:stretchMode="columnWidth"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:verticalSpacing="10dp">
</GridView>
</LinearLayout>
</android.support.v7.widget.LinearLayoutCompat>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
MAINACTIVITY.JAVA
package com.example.steli.hellogridview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridView = (GridView) findViewById(R.id.gridView);
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Toast.makeText(MainActivity.this,"" + position,Toast.LENGTH_SHORT).show();
}
});
}
}
IMAGEADAPTER.JAVA
package com.example.steli.hellogridview;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListAdapter;
/**
* HelloGridView was
* Created by Stelios Papamichail on 11/5/2017.
*
* This file belongs to the com.example.steli.hellogridview package.
*/
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// Create a new ImageView for each item referenced by the Adapter
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if(convertView == null) {
// If it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(180,180));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8,8,8,8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.ssj4_gogeta,
R.drawable.cell_jr_n,
R.drawable.mrsatan_n,
R.drawable.tien,
R.drawable.vegito,
R.drawable.videl
};
}
There is nothing wrong with your Java code. Your XML, however, is pretty messed up.
Why, for example, do you cascade a LinearLayout inside a LinearLayoutCompat inside a NestedScrollView? For scrolling the GridView, you don't need any of this. So take it out.
Also, android:paddingBottom="500dp" is too much. This line pushes part of your GridView outside the top of the screen (at least on the emulator I use). So get rid of that, too (or make the padding smaller).
I don't understand what you want with the AppBarLayout, so I leave it untouched.
Since you probably don't want the GridView to render on top of it, I put the AppBarLayout and the GridView inside a RelativeLayout with android:layout_below="#id/appbar" inside the GridView's XML.
So the XML now looks like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="#+id/toolbar">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="70dp"
android:text="Cards List"
android:textColor="#android:color/holo_blue_light"
android:textSize="40sp" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"></android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<GridView
android:id="#+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/appbar"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="4"
android:stretchMode="columnWidth"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:verticalSpacing="10dp">
</GridView>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

My text is half visible when i want to add a name to my list (SQLite) Android

Hello im making an assignment list with database to add assignments. When i push on the add button i can type my assignment. But i only see half of it. When i click add, it correctly adds the new assignment to the list and i can see the whole text.
How can i solve this ?
This is my XML layout file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="be.ehb.android.arnojansens.DetailGroupsActivity"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/listDetails"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="4.60"></ListView>
<EditText
android:id="#+id/editDetails"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="Details Assignment"/>
<Button
android:id="#+id/btnAddDetailsOpdracht"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Add Details Assignment"/>
</LinearLayout>
</RelativeLayout>
And this is the java of the class
package be.ehb.arnojansens.fragmentexampleii;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import java.util.ArrayList;
public class DetailGroupsActivity extends Activity implements View.OnClickListener {
static Dbhelper opdrDbHelper;
static Button btnAddDetailsOpdracht;
static EditText editDetails;
static ListView listDetails;
static ArrayList<Detail> details;
static long detailId;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail_groups);
btnAddDetailsOpdracht = (Button)findViewById(R.id.btnAddDetailsOpdracht);
editDetails = (EditText)findViewById(R.id.editDetails);
listDetails = (ListView)findViewById(R.id.listDetails);
btnAddDetailsOpdracht.setOnClickListener(this);
opdrDbHelper = new Dbhelper(this);
detailId = (Long)getIntent().getSerializableExtra("detailId");
String opdrachtName = (String)getIntent().getStringExtra("opdrachtName");
this.setTitle(opdrachtName);
if(detailId != -1)
details = opdrDbHelper.findDetailsForOpdracht(detailId);
else
details = new ArrayList<Detail>();
loadDetails();
}
public void loadDetails(){
ArrayAdapter<Detail> adapter =
new ArrayAdapter<Detail>(
this,
android.R.layout.simple_list_item_1,
details);
listDetails.setAdapter(adapter);
}
#Override
public void onClick(View v) {
String detailString = editDetails.getText().toString();
editDetails.setText("");
Detail alb = opdrDbHelper.addAlbum(detailId,detailString);
details.add(alb);
loadDetails();
}
}
Sound to me like the text doesn't fit in the EditText container. Make it wrap_content instead of a fixed size:
<EditText
android:id="#+id/editDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Details Assignment"/>
Also keep in mind that fill_parent was deprecated, use match_parent instead.

How to create dynamically framelayout in linearlayout and using other xml file

I searched for a while and find no awnser and i must say that i'm very new in creating apps
i read the categorys(name, discription) from a sqlite database (i dont know how many categorys are an this database),
now i create a horizontal slider contains linearlayout(horizontal).
in this linearlayout i will create dynamically framelayout (contains custom xml code like other framelayouts, linearlayouts ect.)
i dont know how can i insert the xml ...
i hope someone can help me to find a solution for this problem
--- EDIT ---
the main activity
public class MainActivity extends Activity {
int scr_w, scr_h;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
scr_w = size.x;
scr_h = size.y;
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.menu_box_layout, null, false);
LinearLayout llTest = (LinearLayout)findViewById(R.id.horilila);
//Create the Menu Boxes here
for(int i =1;i<=6; i++){
FrameLayout flTest = new FrameLayout(this);
flTest.addView(v, scr_w, LayoutParams.MATCH_PARENT);
flTest.setId(i + 10);
//Insert the new FrameLayout into the LinearLayout
llTest.addView(flTest);
}
}
the main xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<FrameLayout
android:id="#+id/mailLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/horilila"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
the layout for menu box, that i will insert:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="fill"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<FrameLayout
android:layout_height="match_parent"
android:background="#fab3ff" >
<TextView
android:text="This is a test..." />
</FrameLayout>
</RelativeLayout>
Let's imagine you have a xml, you can get a view from it like that:
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.<your_xml>, null, false);
Then you can add this view to your LinearLayout:
linearLayout.addView(v);

Categories

Resources