Tengo 2 layouts
que se cargan al mismo tiempo, en el 1er layout
activity_main.xml
tengo un listView
y un textView
, en el 2do layout
single_post.xml
tengo 4 textView
que son los que se muestran en la listView
del activity_main.xml
Quiero manipular el color del texto programaticamente de single_post.xml
, intento acceder a el mediante LayoutInflater
pero al parecer no funciona, con el código que tengo a continuación puedo hacer que cambie el color del texto del textView
de activity_main.xml
pero no logro hacer nada con el textView
de single_post.xml
public class MainActivity extends AppCompatActivity {
JSONParser jsonParser = new JSONParser();
ArrayList<HashMap<String, String>> employeeList;
private ProgressDialog pDialog;
private static final String url_tareas = "http://localhost/test/get_employee.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_EMPLOYEES = "employees";
private static final String TAG_NAME = "name";
public static final String TAG_DESIGNATION = "designation";
JSONArray employees = null;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("INICIA ","onCreate 1 ");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
employeeList = new ArrayList<HashMap<String, String>>();
new MainActivity.LoadAllProducts().execute();
list = (ListView) findViewById(R.id.listView);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
Log.d("TERMINA ","onCreate 2 ");
}
class LoadAllProducts extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
Log.d("INICIA ","onPreExecute 3 ");
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Loading...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
Log.d("TERMINA ","onPreExecute 3 ");
}
protected String doInBackground(String... args) {
Log.d("INICIA ","doInBackground 4 ");
List params = new ArrayList();
JSONObject json = jsonParser.makeHttpRequest(url_tareas, "GET", params);
Log.d("All Employees: ", json.toString());
try {
int success =sDesignation= json.getInt(TAG_SUCCESS);"manager";
if (success == 1) {
LayoutInflater employeesinflater = json.getJSONArray(TAG_EMPLOYEESLayoutInflater);
for (int i = 0; i < employees.lengthgetSystemService(); i++) {
JSONObject c = employeesContext.getJSONObject(iLAYOUT_INFLATER_SERVICE);
StringView nameview = cinflater.getStringinflate(TAG_NAME);
String designation = cR.getString(TAG_DESIGNATION);
Loglayout.d(""single_post,"designation1= "+designation);
HashMap map = new HashMap(null);
TextView map.putestatus_SINGLE_POST=(TAG_NAME, nameTextView);
mapview.putfindViewById(TAG_DESIGNATION, designation);
employeeListR.add(map);
Logid.d("INICIA ","designation2= "+designationtxt_designation_SINGLE_POST);
TextView designationN = estatus_ACTIVITY_MAIN=(TextView)findViewById(R.id.txt_designationtxt_designation_ACTIVITY_MAIN);
if(designationsDesignation.equals("manager")){
LogToast.dmakeText("ENTRA AL IF ","designation3= "+designation);
//CAMBIA EL COLOR DEL TEXTO designationN
}LogMainActivity.d("CONTINUA"this,"designation= "+designation);
}
}
} catch (JSONException e) {
"YES "+sDesignation, eToast.printStackTrace(LENGTH_LONG);
Log.eshow("","Error= "+e);
}
Logestatus_ACTIVITY_MAIN.dsetTextColor("TERMINA ","doInBackground 4 "Color.RED);
return null;
}
protected void onPostExecute(String file_url) {
Logestatus_SINGLE_POST.dsetTextColor("INICIA ","onPostExecute 5 ");
pDialogColor.dismiss(RED);
runOnUiThread(new Runnable() {
public void run() }else{
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapterToast.makeText(
MainActivity.this,
employeeList,
R.layout.single_post,
new String[] {
TAG_NAME,
TAG_DESIGNATION,
"NO }"+sDesignation,
new int[] {
RToast.idLENGTH_LONG).txt_name,show();
Restatus_ACTIVITY_MAIN.idsetTextColor(Color.txt_designation,
}GREEN);
listestatus_SINGLE_POST.setAdaptersetTextColor(adapterColor.GREEN);
}
});
Log.d("TERMINA ","onPostExecute 6 ");
}
}
}
<?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"
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.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_designation2"txt_designation_ACTIVITY_MAIN"
android:textSize="18sp"
android:textColor="@android:color/black" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_designation2"
android:layout_alignStart="@+id/txt_designation2"
android:layout_marginTop="32dp"
android:id="@+id/button" />
</RelativeLayout>
<?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"
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="1dp">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"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>
txt_designation
no lo tengo en el layot activity_main
osea esta en el layout single_post
La idea es obtener el valor de un textView
que se carga en otro layout
pero solo puedo obtener el valor de los textView
que se cargan en el layout
que se indique en el método setContentView();
Esto me muestra el Logcat:
03-02 10:25:49.879 30713-30736/com.example.user.testbd D/All Employees:: {"success":1,"employees":[{"designation":"manager","name":"rick"}]}
[ 03-02 10:25:49.879 30713:0x7810 D/ ]
designation1= manager
03-02 10:25:49.879 30713-30736/com.example.user.testbd D/INICIA: designation2= manager
03-02 10:25:49.880 30713-30736/com.example.user.testbd D/ENTRA AL IF: designation3= manager
03-02 10:25:49.880 30713-30736/com.example.user.testbd D/SALE DEL IF: designation= manager
03-02 10:25:49.880 30713-30736/com.example.user.testbd D/TERMINA: doInBackground 4
03-02 10:25:49.891 30713-30713/com.example.user.testbd D/INICIA: onPostExecute 5
Pero si en la parte de código del MainActivity que tengo comentada cambio el color del texto e intento hacer esto:
TextView designationN = (TextView)findViewById(R.id.txt_designation2);
if(designation.equals("manager")){
Log.d("ENTRA AL IF ","designation3= "+designation);
//CAMBIA EL COLOR DEL TEXTO designationN
designationN.setTextColor(Color.RED);
}
Lo hago de esta forma porque en esa parte del código tengo el nuevo valor de txt_designation