How to add image view and text view to a linear layout - android

my xml is like follow I want to add image view and text view programmatically to given xml.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="25dip" >
<TextView
android:id="#+text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dip"
android:text="#string/app_name"
android:textSize="24.5sp" />
</LinearLayout>
but I want output like following programmatically ie a linear layout contain image view and old text view and add that linearlayout below to new textview.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="25dip" >
<TextView
android:id="#+name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dip"
android:text="#string/app_name"
android:textSize="24.5sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="25dip" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="60dp"
android:layout_marginBottom="12dip"
android:src="#drawable/app_icon_big" />
<TextView
android:id="#+text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dip"
android:text="#string/app_name"
android:textSize="24.5sp" />
</LinearLayout>
</LinearLayout>

Try this way,hope this will help you to solve your problem.
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/outerLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="25dp" >
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:text="#string/app_name"
android:textSize="24.5sp" />
</LinearLayout>
MainActivity.java
public class MyActivity extends Activity {
private LinearLayout outerLinearLayout;
private TextView text1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
outerLinearLayout = (LinearLayout) findViewById(R.id.outerLinearLayout);
text1 = (TextView) findViewById(R.id.text1);
LinearLayout innerLinearLayout = new LinearLayout(this);
ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.bottomMargin=12;
imageView.setLayoutParams(params);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setImageResource(R.drawable.ic_launcher);
innerLinearLayout.addView(imageView);
TextView textView = new TextView(this);
textView.setTextSize((float) 24.5);
textView.setText("New Text View");
textView.setLayoutParams(params);
outerLinearLayout.removeAllViews();
innerLinearLayout.addView(text1);
outerLinearLayout.addView(textView);
outerLinearLayout.addView(innerLinearLayout);
}
}

change inner layout
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="25dip" >
By
<LinearLayout
android:id="#+id/internal_image_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="25dip"
android:visibility="gone" >
Then whenEver you want to show just
findViewById(R.id.internal_image_textView).setVisibility(View.VISIBLE)

Related

Adding Views dynamically in Linear Layout in Fragment

I am trying to add TextView to the nested linearLayout in fragmentin onCreateView, I don't know if this is the correct approach or not, new to android!
Thanks in advance
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_screen_slide_page, container, false);
List<LifeBerrysXmlParser.Item> items = (ArrayList<LifeBerrysXmlParser.Item>) getArguments().getSerializable("List");
TextView mainHeading = (TextView) rootView.findViewById(R.id.mainHeading);
ImageView mainImage = (ImageView) rootView.findViewById(R.id.articleMainImage);
LinearLayout articleLayout = (LinearLayout) rootView.findViewById(R.id.articleLayout);
TextView tev = new TextView(getActivity());
tev.setText("Hello..............");
articleLayout.addView(tev);
LifeBerrysXmlParser.Item item = items.get(getArguments().getInt("position"));
String articleMainHeading = item.mainHeading;
String articlemainImage = item.mainImage;
mainHeading.setText(articleMainHeading);
if (!articlemainImage.isEmpty()) {
Picasso.with(getContext()).load(articlemainImage).into(mainImage);
}
return rootView;
}
can anyone please help me what I am doing wrong?
here is my xml for the fragment
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:id="#+id/content"
android:padding="1dp"
android:layout_weight="1"
android:background="#000000"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
android:scrollIndicators="right">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/articleMainImage"
android:maxHeight="300dp"/>
<TextView
style="?android:textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeightLarge"
android:layout_weight="1"
android:lineSpacingMultiplier="1.2"
android:id="#+id/mainHeading"
android:textColor="#ff6435"
android:clickable="false"
android:layout_gravity="center"
android:layout_centerInParent="true"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/articleLayout"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Read More"
android:textSize="15dp"
android:textStyle="bold"
android:layout_gravity="center"
android:clickable="true"
android:focusable="false"
android:gravity="center"
android:onClick="readMore"
android:padding="1dp"
android:textColor="#android:color/holo_green_light" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
You have mistake in your article layout. Your article layout has horizontal orientation, and it's child TextView has match_parent width, so when you add new child, it'll be outside the screen. Change orientation to vertical:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/articleLayout"
android:orientation="vertical"> <---- Change this line
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Read More"
android:textSize="15dp"
android:textStyle="bold"
android:layout_gravity="center"
android:clickable="true"
android:focusable="false"
android:gravity="center"
android:onClick="readMore"
android:padding="1dp"
android:textColor="#android:color/holo_green_light" />
</LinearLayout>

add view dynamically above two already created button in relative layout in android

this is my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/linearlayout"
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="evip.gohybrid.com.evip.ShowBarcode">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/btnaddtoprofile"
android:text="Add to Profile"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginTop="10dp"
android:gravity="center"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/btncancel"
android:text="Cancel"
android:textStyle="bold"
android:textSize="20dp"
android:layout_below="#+id/btnaddtoprofile"
android:gravity="center"/>
this is my code:
Bitmap bitmap = null;
ImageView iv = new ImageView(this);
try {
bitmap = encodeAsBitmap(code, BarcodeFormat.CODE_128, 600, 300);
iv.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
relativelayout.addView(iv);
//barcode text
TextView tv = new TextView(this);
tv.setGravity(Gravity.CENTER_HORIZONTAL);
tv.setText(code);
tv.setTextSize(25);
relativelayout.addView(tv);
i want to add imageview on top and then textview dynamically and then the two button which is in my layout file ....how can i do it...? can anyone give me suggestion..?
You can do it in this way:
<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:orientation="vertical"
android:weightSum="100" >
<LinearLayout
android:id="#+id/your_dinamyc_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="70"
>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="30"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/btnaddtoprofile"
android:text="Add to Profile"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginTop="10dp"
android:gravity="center"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/btncancel"
android:text="Cancel"
android:textStyle="bold"
android:textSize="20dp"
android:layout_below="#+id/btnaddtoprofile"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
I have not added dinamycally an imageview I added two textviews instead of:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout your_dinamic_layout=(LinearLayout)findViewById(R.id.your_dinamyc_layout);
TextView tv = new TextView(this);
tv.setGravity(Gravity.CENTER_HORIZONTAL);
tv.setText("code");
tv.setTextSize(25);
your_dinamic_layout.addView(tv);
TextView tv2 = new TextView(this);
tv2.setGravity(Gravity.CENTER_HORIZONTAL);
tv2.setText("code 2");
tv2.setTextSize(30);
your_dinamic_layout.addView(tv2);
}
}
and the result is:

how to show custom layout in my main layout?

im using custom listview in my main layout from here https://github.com/NikolaDespotoski/DoubleTapListViewHandler/tree/master/src/com/nikola/despotoski/doubletaplistview but problem is this wil create custom programicaly layout but in my code i already set content setContentView(R.layout.bid); so how do i add new custom layout in my main layout?? help me what will i do??
private CustomListView bidlist = null;
public class BidSchema extends BackBaseActivity implements OnItemDoubleTapLister {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.bid);
bidlist = new CustomListView(this);
bidlist.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
setContentView(bidlist);
back = (ImageView) findViewById(R.id.bidback);
bottomlayout = (RelativeLayout)findViewById(R.id.bottom_layout);
scroll_down = (ImageView) findViewById(R.id.down);
scroll_up = (ImageView) findViewById(R.id.up);
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="wrap_content"
android:background="#drawable/bg2" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/top_bar1"
android:contentDescription="#string/contentdesc" />
<ImageView
android:id="#+id/bidback"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginLeft="3dp"
android:background="#drawable/back_arr"
android:contentDescription="#string/contentdesc" />
<ImageView
android:id="#+id/iconpic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="4dp"
android:layout_centerHorizontal="true"
android:background="#drawable/treasure"
android:contentDescription="#string/contentdesc" />
<TextView
android:id="#+id/bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:background="#drawable/bar"
android:contentDescription="#string/contentdesc"
android:gravity="center"
android:text="Bid"
android:textColor="#000000"
android:textSize="22sp" />
<LinearLayout
android:id="#+id/jobhead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bar"
android:layout_marginTop="10dp"
android:layout_marginLeft="10sp"
android:orientation="horizontal" >
<TextView
android:id="#+id/jobDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="20dp"
android:textColor="#ffffff"
android:textSize="22sp"
android:gravity="left"
android:text="Plot"
android:textStyle="bold" />
<TextView
android:id="#+id/jobpick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="right"
android:paddingRight="50dp"
android:text="Job"
android:textColor="#ffffff"
android:textSize="22sp"
android:textStyle="bold" />
</LinearLayout>
<ListView
android:id="#+id/bidlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/jobhead"
android:layout_marginBottom="10dp"
android:layout_above="#+id/bottomBar"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:background="#drawable/fields_bg"
android:visibility="visible" >
</ListView>
<include
android:id="#+id/bottomBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
layout="#layout/bottom" />
</RelativeLayout>
If you have implement custom Listview then you should change this.
setContentView(R.layout.bid);
bidlist = new CustomListView(this);
bidlist.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
setContentView(bidlist);
to
bidlist = new CustomListView(this);
bidlist.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
setContentView(bidlist);
UPDATE:
RelativeLayout rootLayout = (RelativeLayout) findViewById(R.id.layout);
bidlist = new CustomListView(this);
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
rootLayout.addView(bidlist, rlp);
Because you can't call setContentView() two times. So you have to add it in your parent Relative Layout. so check that.
Give an id to your parent RelativeLayout as below to add new view to this layout later...
<?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="wrap_content"
android:background="#drawable/bg2"
android:id="#+id/layout" >
..........
</RelativeLayout >
Now, add your bidlist to the parent layout as below...
RelativeLayout rootLayout = (RelativeLayout) findViewById(R.id.layout);
bidlist = new CustomListView(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
rootLayout.addView(bidlist, lp);
You don't setContentView.
If main activity show posted xml, just make Adapter implements baseAdapter, and then just listview.setAdapter( you make adapter)

Dynamically change the margins of RelativeLayout which is getting inflated via xml

I am tryin to add ten relativeLayouts dynamically by inflating the xml , but the relative layouts getting overlapped. how to change the margins of the inflating xml dynamically via code.
Below is the code reuse.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/aaa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
>
<ImageView
android:id="#+id/image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:scaleType="centerCrop"
android:src="#drawable/ballaya" />
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="50dp"
android:layout_marginTop="12dp"
android:layout_weight="1"
android:text="Srimannarayana earns Rs 8.65 cr on day 1"
android:textColor="#FFFFFF"
android:textSize="11sp"
android:textStyle="bold" />
<View
android:id="#+id/seperator"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_below="#+id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="#FFFFFF" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="#drawable/popover_bg_rghtarw" />
</RelativeLayout>
code of item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#06516E" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="20dp"
android:background="#49C7F9">
<TextView
android:id="#+id/HeadLines"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Latest News"
android:textColor="#FFFFFF"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/newsLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="30dp" >
</RelativeLayout>
</RelativeLayout>
Java Code
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.item);
newsLayout =(RelativeLayout)findViewById(R.id.newsLayout);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout row[] = new RelativeLayout[10];
TextView text[]= new TextView[10];
for(int i=0;i<10;i++){
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
row[i] = (RelativeLayout) inflater.inflate(R.layout.reuse,null);
params.setMargins(0, 50, 0, 0);
newsLayout.addView(row[i],params);
text[i]= (TextView) row[i].findViewById(R.id.text);
text[i].setText("AAAAAAA");
}
You can use LinearLayout instead of RelativeLayout for newsLayout and make the orientation as VERTICAL.
And instead of newsLayout =(RelativeLayout)findViewById(R.id.newsLayout);
write: newsLayout =(LinearLayout)findViewById(R.id.newsLayout);
And rest of the code will be as it is.
This will solve your problem.

Android: Custom view from xml layout

i would like to create a custom View (subclass of the View class) and use a layout xml resource.
I want something like this:
public class CustomView extends LinearLayout {
public CustomView(Context context) {
super(context);
LayoutInflater mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mInflater.inflate(R.layout.tweet, this, true);
}
This actually creates a View with the right height and width (a ScrollView with a list of those has exactly the expected length and scrollbars) but they are empty (black) even though the xml layout contains a lot of TextViews.
This is my xml layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tweet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
android:background="#ffffff">
<TextView
android:text="User"
android:id="#+id/tvusername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textStyle="bold">
</TextView>
<View
android:layout_width="5dip"
android:layout_height="1dip">
</View>
<TextView
android:text="userscreenname"
android:id="#+id/tvuserscreenname"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
<TextView
android:text="0s"
android:id="#+id/tvtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true">
</TextView>
</RelativeLayout>
<TextView
android:text="Tweet Content"
android:id="#+id/tvcontent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000">
</TextView>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#ffffff">
</View>
<TextView
android:text="Retweet by"
android:id="#+id/tvrtby"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
This is my main layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/scrollView1"
android:orientation="vertical"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:id="#+id/timeline"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#ffffff">
<TextView
android:id="#+id/tvoutput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
This is how I add the custom view to my main view:
Not working (what I try to achieve):
TweetView ctweet = new TweetView(getApplicationContext(),tweet);
timeline.addView(ctweet);
My current solution (works, but uses no custom view):
View vtweet = View.inflate(getApplicationContext(), R.layout.tweet,null);
TextView tvusername = (TextView) vtweet.findViewById(R.id.tvusername);
TextView tvuserscreenname = (TextView) vtweet.findViewById(R.id.tvuserscreenname);
TextView tvcontent = (TextView) vtweet.findViewById(R.id.tvcontent);
TextView tvtime = (TextView) vtweet.findViewById(R.id.tvtime);
tvusername.setText(tweet.getUser().getName());
tvuserscreenname.setText('#' + tweet.getUser().getScreenName());
tvcontent.setText(tweet.getText());
//tvtime.setText(ctweet.tvtime.getText());
timeline.addView(vtweet);
you can use this in your xml just like any other view like <TextView
try <packageName.ClassName ie something like <com.example.CustomView
Probably you have to set the Layout Params of your TweetView object.
LinearLayout.LayoutParams fieldparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f);
ctweet.setLayoutParams(fieldparams);

Categories

Resources