UPDATE
I have 2 layouts
that are loaded at the same time, in the 1st layout
activity_main.xml
I have a listView
and a textView
, in the 2nd layout
single_post.xml
I have 4 textView
that are those shown in listView
of activity_main.xml
I want to manipulate the color of the text programmatically from single_post.xml
, I try to access it using LayoutInflater
but apparently it does not work, with the code I have below I can change the text color of textView
of activity_main.xml
but I can not do anything with the textView
of single_post.xml
On the MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String sDesignation= "manager";
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.single_post, null);
TextView estatus_SINGLE_POST=(TextView)view.findViewById(R.id.txt_designation_SINGLE_POST);
TextView estatus_ACTIVITY_MAIN=(TextView)findViewById(R.id.txt_designation_ACTIVITY_MAIN);
if(sDesignation.equals("manager")){
Toast.makeText(MainActivity.this, "YES "+sDesignation, Toast.LENGTH_LONG).show();
estatus_ACTIVITY_MAIN.setTextColor(Color.RED);
estatus_SINGLE_POST.setTextColor(Color.RED);
}else{
Toast.makeText(MainActivity.this, "NO "+sDesignation, Toast.LENGTH_LONG).show();
estatus_ACTIVITY_MAIN.setTextColor(Color.GREEN);
estatus_SINGLE_POST.setTextColor(Color.GREEN);
}
}
}
In the activity_main.xml
<?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:id="@+id/activity_main"
tools:context="com.example.user.testbd.MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/listView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="37dp" />
<TextView
android:text="manager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/listView"
android:layout_alignParentStart="true"
android:layout_marginStart="91dp"
android:layout_marginTop="75dp"
android:id="@+id/txt_designation_ACTIVITY_MAIN"
android:textSize="18sp"
android:textColor="@android:color/black" />
</RelativeLayout>
In the single_post.xml
<?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:id="@+id/activity_main3">
<TextView
android:text="Name:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="71dp"
android:id="@+id/textView2"
android:textSize="18sp"
android:textColor="@android:color/black" />
<TextView
android:text="Designation:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_alignStart="@+id/textView2"
android:layout_marginTop="46dp"
android:id="@+id/textView3"
android:textSize="18sp"
android:textColor="@android:color/black" />
<TextView
android:text="designation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/textView3"
android:layout_alignStart="@+id/txt_name"
android:id="@+id/txt_designation_SINGLE_POST"
android:textSize="18sp"
android:textColor="@android:color/black" />
<TextView
android:text="name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="86dp"
android:id="@+id/txt_name"
android:textSize="18sp"
android:textColor="@android:color/black"
android:layout_above="@+id/textView3"
android:layout_alignParentEnd="true" />
</RelativeLayout>
The idea is to obtain the value of a textView
that is loaded in another layout
but I can only get the value of the textView
that are loaded in the layout
that is indicated in the method setContentView();