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

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);

Related

Add editTexts to a layout dynamically using an add button in android

I am having a layout with a single editText in it,below the editText I added a add button. Now my question is when I click the add button I need to get another editText below the editText and has to repeat the same.Please anyone help, Thank you.
activity_main.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">
<LinearLayout
android:id="#+id/ll_edit_texts_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/buttonAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD" />
</LinearLayout>
and put following code in your Activity
final LinearLayout llEditTextsContainer = (LinearLayout) view.findViewById(R.id.ll_edit_texts_container);
Button buttonAdd = (Button) view.findViewById(R.id.buttonAdd);
buttonAdd.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
EditText editText = new EditText(getActivity());
//editText.setId(); you should set id smartly if you wanted to use data from this edittext
llEditTextsContainer.addView(editText);
}
});
First of all create a container view in your main layout which is going to hold the new Edittexts.
<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: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="com.example.vuclip.dynamictextedit.MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/addTextView"
android:text="Add EditText"
android:onClick="onClick"
/>
<TableLayout
android:id="#+id/containerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
</TableLayout>
Here, on pressing the button, new Edittexts will be created and added into the TableLayout.
Now create a new Layout which will hold your edittext(I called this file new_layout.xml).
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="#+id/newEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Now add this layout into your main activity.
public class MainActivity extends AppCompatActivity {
TableLayout container;
static int rowIndex = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
container = (TableLayout) findViewById(R.id.containerLayout);
}
public void onClick(View view) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View newRowView = inflater.inflate(R.layout.new_layout,null);
container.addView(newRowView,rowIndex);
rowIndex++;
}}

Android : Get fragment's background color

I am trying to get the color set on android:background attribute from a fragment's XML file through an activity's onCreate method.
I used both the getSolidColor() and the getgetDrawingCacheBackgroundColor() methods but both of them return the value of the color corresponding to the Layout containing the fragment..
Here is the Activities code part :
private SeekBar seekBar;
private View fragmentOne;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
fragmentOne = findViewById(R.id.fragment1);
seekBar = (SeekBar) findViewById(R.id.seekBar1);
fragmentOne.getDrawingCacheBackgroundColor()
the fragment's xml file,
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/colorAccent"
android:padding="5dp"/>
And the activity_main xml file containing the above, and also 4 other fragments and a seekbar:
<?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:background="#color/black">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<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:layout_weight="2"
android:orientation="vertical"
android:padding="5dp"
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:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.maryland.modernartui_nikos.MainActivity">
<fragment
android:id="#+id/fragment1"
android:name="com.maryland.modernartui_nikos.FragmentOne"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
tools:layout="#layout/fragment_fragment_one" />
<fragment
android:id="#+id/fragment2"
android:name="com.maryland.modernartui_nikos.FragmentTwo"
android:layout_width="match_parent"
android:layout_height="117dp"
tools:layout="#layout/fragment_fragment_two" />
</LinearLayout>
<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:layout_weight="2"
android:orientation="vertical"
android:padding="2dp"
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:showDividers="beginning|middle|end"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.maryland.modernartui_nikos.MainActivity">
<fragment
android:id="#+id/fragment3"
android:name="com.maryland.modernartui_nikos.FragmentThree"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
tools:layout="#layout/fragment_fragment_three" />
<fragment
android:id="#+id/fragment4"
android:name="com.maryland.modernartui_nikos.FragmentFour"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4"
tools:layout="#layout/fragment_fragment_four" />
<fragment
android:id="#+id/fragment5"
android:name="com.maryland.modernartui_nikos.FragmentFive"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4"
tools:layout="#layout/fragment_fragment_five" />
</LinearLayout>
</LinearLayout>
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="10"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
The method returns the value from the RelativeLayout of activity_main.xml and not from fragment_one.xml .Why?
Found a solution to this problem :
ColorDrawable colorDrawableOne = (ColorDrawable) fragmentOne.getBackground();
ColorDrawable colorDrawableTwo = (ColorDrawable) fragmentTwo.getBackground();
ColorDrawable colorDrawableFour = (ColorDrawable) fragmentFour.getBackground();
ColorDrawable colorDrawableFive = (ColorDrawable) fragmentFive.getBackground();
final int colorOne = colorDrawableOne.getColor();
final int colorTwo = colorDrawableTwo.getColor();
final int colorFour = colorDrawableFour.getColor();
final int colorFive= colorDrawableFive.getColor();
The fragment's getBackground() method must be called and stored to a ColorDrawable variable with type casting.
Then you can call the getColor() methdod of this object to get the desired color.
put id on a relative_layout, use findViewById() to get relative_layout, where you can use view.getBaackground().

Textview in Fragment not working

I am currently working on adding tabs into my activity. For the same, I am using the Google SlidingTabLayout and SlidingTabStrip.
My fragment xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" > >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textViewTab" />
</RelativeLayout>
My contents xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.musicisfun.allaboutfootball.MainActivity"
tools:showIn="#layout/activity_main">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.example.musicisfun.allaboutfootball.tabs.SlidingTabLayout
android:layout_width="match_parent"
android:id="#+id/tabs"
android:layout_height="wrap_content">
</com.example.musicisfun.allaboutfootball.tabs.SlidingTabLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
/>
</LinearLayout>
</RelativeLayout>
and my code looks like this:
public static class TabFragment extends Fragment{
public static TabFragment getInstance(int position){
TabFragment tabFragment = new TabFragment();
Bundle bundle = new Bundle();
bundle.putInt("site",position);
tabFragment.setArguments(bundle);
return tabFragment;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View layout = inflater.inflate(R.layout.fragment_tab,container,false);
TextView textViewTab = (TextView) layout.findViewById(R.id.textViewTab);
Bundle bundle = getArguments();
if (bundle!=null){
textViewTab.setText("Current Tab is" + bundle.getInt("site"));
}
return layout;
}
}
My fragment adaptor looks like this:
class TabPagerAdaptor extends FragmentPagerAdapter{
String[] tab_names;
public TabPagerAdaptor(FragmentManager fm) {
super(fm);
tab_names=getResources().getStringArray(R.array.feed_names);
}
#Override
public Fragment getItem(int position) {
TabFragment tabFragment = TabFragment.getInstance(position);
return tabFragment;
}
#Override
public CharSequence getPageTitle(int position) {
return tab_names[position];
}
#Override
public int getCount() {
return 2;
}
}
and this is how i am invoking the tabs:
mViewPager= (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(new TabPagerAdaptor(getSupportFragmentManager()));
mTabs = (SlidingTabLayout) findViewById(R.id.tabs);
mTabs.setViewPager(mViewPager);
But when I run the code, I can't find the textview being shown even though two tabs are working fine.
You cannot view your textView because the height of the ViewPager is 0dp in your xml -
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
/>
you have to change that to either wrap_content or match_parent-
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Also, Your LinearLayout's orientation is horizontal and the width of SlidingTabLayout is match_parent. SlidingTabLayout is occupying whole screen width leaving no room to display Viewpager.
Your LinearLayout's orientation should be vertical not horizontal
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.example.musicisfun.allaboutfootball.tabs.SlidingTabLayout
android:layout_width="match_parent"
android:id="#+id/tabs"
android:layout_height="wrap_content">
</com.example.musicisfun.allaboutfootball.tabs.SlidingTabLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>

Fragment layout not being inflated

I have an application where the device switches fragments depending on your orientation. Each one has a text view and an inflater in the respective java class. The application runs fine, but doesn't inflate the fragments. I am a beginner when it comes to fragments. Here is my code:
MainActivity.java
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Configuration configInfo = getResources().getConfiguration();
if(configInfo.orientation == Configuration.ORIENTATION_LANDSCAPE){
LandscapeFragment fragmentLandscape = new LandscapeFragment();
fragmentTransaction.replace(android.R.id.content, fragmentLandscape);
}else{
PortraitFragment fragmentPortrait = new PortraitFragment();
fragmentTransaction.replace(android.R.id.content, fragmentPortrait);
}
fragmentTransaction.commit();
}
}
activity_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: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=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/landscape_fragment" />
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/portrait_fragment" />
</RelativeLayout>
LandscapeFragment.java
public class LandscapeFragment extends Fragment{
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
System.out.println("Landscape Fragment Created");
View v = inflater.inflate(R.layout.landscape_fragment, container, false);
return v;
}
}
landscape_fragment.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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/landscape_text_view"
android:textSize="30sp" />
</RelativeLayout>
PortraitFragment.java
public class PortraitFragment extends Fragment{
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
System.out.println("Portrait Fragment Created");
View v = inflater.inflate(R.layout.portrait_fragment, container, false);
return v;
}
}
portrait_fragment.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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin">
<TextView android:text="#string/portrait_text_view" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="30sp"/>
</RelativeLayout>
When you need change the layout at run time , you should not declare the fragment inside the activity's layout file. Replace your activity_main.xml with
<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=".MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_content" />
</RelativeLayout>
and change your fragment creation code to
if(configInfo.orientation == Configuration.ORIENTATION_LANDSCAPE){
LandscapeFragment fragmentLandscape = new LandscapeFragment();
fragmentTransaction.replace(R.id.main_content, fragmentLandscape);
}else{
PortraitFragment fragmentPortrait = new PortraitFragment();
fragmentTransaction.replace(R.id.main_content, fragmentPortrait);
}
the doc here will help you understand more about fragments
Do not code anything in MainActivity,
As the link given by #jobcrazy do it directly in xml:
<fragment
android:name="yourpackage.PortraitFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/landscape_fragment" />
<fragment
android:name="yourpackage.LandscapeFragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/portrait_fragment" />
That should solve it!

Dynamically adding views missing scrollbar

I am adding views dynamically like this:
LayoutInflater layoutInflater =
(LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.dynamicabout, null);
TextView textOut = (TextView)addView.findViewById(R.id.aboutcontent);
textOut.setText(strings.get(index));
((ViewGroup) v).addView(addView);
However, once we get to the bottom of the screen and beyond, there's no scrollbar.
I tried using the ScrollView, but that doesn't do anything.
dynamicabout.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="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/aboutcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
about.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:paddingLeft="#dimen/stdpadding"
android:paddingRight="#dimen/stdpadding"
android:paddingBottom="#dimen/stdpadding"
android:paddingTop="#dimen/stdpadding"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ScrollView>
</LinearLayout>
What you need to do is you need to have Parent and Child view. Add child to the Parent. Parent is LinearLayout in ScrollView in dynamicabout.xml. Child is about XML. Inflate about XML on the runtime and Add it into Parent View (LinearLayout in ScrollView).
P.S. > Set an ID for the Parent Layout in order to be able to add views inside it, as far as I see it doesn't have ID.
<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:paddingLeft="#dimen/stdpadding"
android:paddingRight="#dimen/stdpadding"
android:paddingBottom="#dimen/stdpadding"
android:paddingTop="#dimen/stdpadding"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/linear
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ScrollView>
</LinearLayout>
////////////////////////////////////////////////
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/aboutcontent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"/>
</LinearLayout>
</RelativeLayout>
//////////////////////////////////////////////////////////////
LinearLayout linear=(LinearLayout)findviewbyId(R.id.linear);
LayoutInflater layoutInflater =
(LayoutInflater) getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.dynamicabout, null);
TextView textOut = (TextView)addView.findViewById(R.id.aboutcontent);
textOut.setText(strings.get(index));
linearview.addView(addView);
please chk this code:

Categories

Resources