Reputation: 700
In my android app i have been using the RelativeLayout and inflater. so i need to set the text in textView, which i have used with Inflater, but i cannot set the text by code.
XML file activity_title
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="10dp"
android:layout_height="match_parent"
android:background="#000000" >
<TextView
android:id="@+id/text_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="Text" />
</RelativeLayout>
2 xml file
<RelativeLayout
android:id="@+id/rel_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/linearLayout1"
android:layout_toRightOf="@+id/linearLayout1"
>
</RelativeLayout>
so this is the code, which using the inflater
relativeLayout = (RelativeLayout) findViewById(R.id.rel_container);
((ViewGroup) relativeLayout).removeAllViews();
for (int i = 0; i < titleCalendar.length; i++) {
getApplicationContext();
vi= (LayoutInflater)
getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.activity_title, null);
textViewC = (TextView) v.findViewById(R.id.text_title);
textViewC.setText("sdfsfasfasfasfasf");
textViewC.setTextColor(Color.parseColor("#ffffff"));
final RelativeLayout.LayoutParams params = new
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, addcnvrtTime);
textViewC.setLayoutParams(params);
((ViewGroup) relativeLayout).addView(v, 0, params);
}
I cannot see the text, which i set on that textview
Upvotes: 0
Views: 1543
Reputation: 2717
This is to get Inflater elements:
LayoutInflater inflater = getLayoutInflater();
View customView = inflater.inflate(R.layout.YOUR_LAYOUT_INFLATER, null);
TextView text = (TextView)customView.findViewById(R.id.YOUR_TEXT_VIEW);
text.setText("BlaBlaBlaBlaBla");
Why not put TextView direct inside the Layout and simply do
TextView text = (TextView)findViewById(R.id.YOUR_TEXT_VIEW);
text.setText("BlaBlaBlaBlaBla");
?
Upvotes: 2