Android:ListView文本颜色是不可见的,我不希望它不可见

时间:2014-04-11 07:40:30

标签: java android xml listview text

我的ListView上有两个EditText和一个Layout。我必须先显示一个,然后点击其中一个选项后我必须显示另一个ListView

一切正常,但是当我必须显示第二个ListView时出现问题,我看不到选项的文字,我只能在按下选项时看到文字它被按下我可以看到白色的文字(背景颜色相同)。

我不明白为什么会发生这种情况,因为我将ListView定义为第二个,但其中一个显示黑色文本,第二个显示白色。我不会更改任何ListView属性,除了它们的位置。我把代码和xml文件放在一边,如果有帮助的话,谢谢!

以下是我班级的一部分,全部与ListView s:

相关
public class activitySelectEnvironment extends Activity{

ListView lvEnvironment;
ListView lvPlanes;


@SuppressLint("InlinedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE);
    setContentView(R.layout.activity_select_environment);
    myIntent = new Intent();

    lvEnvironment = (ListView)findViewById(R.id.listViewEnvironment);       
    lvPlanes = (ListView)findViewById(R.id.listViewPlane);

    //lvPlanes.setVisibility(View.GONE);
    lvEnvironment.setVisibility(View.VISIBLE);
}   

@Override
public void onResume()
{   
    super.onResume();       
    registerReceiver(receptorBroadcast, filtroIntents); 
    if (!verificaConexion(getApplicationContext())) 
    {     
        Toast.makeText(getApplicationContext(), "No hay conexión a Internet.", Toast.LENGTH_SHORT).show();  
    } 
    else
    {
        RequestEdificios re = new RequestEdificios(this, IP, user, password);       

        re.execute("");
    }
}

@Override
public void onPause()
{
    super.onPause();
    this.unregisterReceiver(receptorBroadcast);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

/*******************************************************/
    /********        Receptor de broadcast      ********/
    /*******************************************************/
public class ReceptorBroadcast extends BroadcastReceiver
    {       
        @Override
        public void onReceive(Context arg0, Intent intent)
        {
            if(RequestEdificios.ACTION_SINCRONIZACION_FINALIZADA.equals(intent.getAction()))
            {
                buildingId = intent.getStringArrayListExtra("id_edificio");
                buildingArray = intent.getStringArrayListExtra("buildingArray");
                RefrescaPantalla(intent.getStringArrayExtra("edificios"));
            }
            if(RequestPlanes.ACTION_SINCRONIZACION_PLANES_FINALIZADA.equals(intent.getAction()))
            {                           
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_expandable_list_item_1, android.R.id.text1, intent.getStringArrayExtra("planos"));             

                lvEnvironment.setVisibility(View.GONE);
                //lvPlanes.setVisibility(View.VISIBLE);

                //Assign adapter to ListView
                lvPlanes.setAdapter(adapter); 

                    //ListView Item Click Listener
                lvPlanes.setOnItemClickListener(new OnItemClickListener() 
                {
                    /* code */
                    }
            });
        }
        if(InsertPaths.ACTION_SINCRONIZACION_INSERT_FINALIZADA.equals(intent.getAction()))
        {
            Toast.makeText(getApplicationContext(), "Plano subido a la base de datos." , Toast.LENGTH_LONG).show();

            myIntent.setClass(activitySelectEnvironment.this, activitySelectFoot.class);                 
            startActivity(myIntent);
        }
    }
} 

private void RefrescaPantalla(String[] result)
{       
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, android.R.id.text1, result);

        //Assign adapter to ListView
    lvEnvironment.setAdapter(adapter); 

        //ListView Item Click Listener
    lvEnvironment.setOnItemClickListener(new OnItemClickListener() 
    {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
        {
            if (!verificaConexion(getApplicationContext())) 
            {     
                Toast.makeText(getApplicationContext(), "No hay conexión a Internet.", Toast.LENGTH_SHORT).show();  
            } 
            else
            {       
                /* code */
            }
        }
    });
}   

public static boolean verificaConexion(Context ctx) 
{     
    boolean bConectado = false;     
    ConnectivityManager connec = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);     
    // No sólo wifi, también GPRS     
    NetworkInfo[] redes = connec.getAllNetworkInfo();     
    // este bucle debería no ser tan ñapa     
    for (int i = 0; i < 2; i++) 
    {         
        // ¿Tenemos conexión? ponemos a true         
        if (redes[i].getState() == NetworkInfo.State.CONNECTED) 
        {             
            bConectado = true;         

        }    
    } 
    return bConectado;      
}
} 

以下是布局的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="match_parent" >

 <TextView
     android:id="@+id/txtHead"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentLeft="true"
     android:layout_alignParentTop="true"
     android:layout_marginLeft="78dp"
     android:layout_marginTop="39dp"
     android:background="@drawable/edittext_rounded_corners"
     android:text="Primero indique a que planta pertenece y después seleccione el edificio:"
     android:textAppearance="?android:attr/textAppearanceLarge"
     android:textSize="25dp" />

 <ListView
     android:id="@+id/listViewEnvironment"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/txtHead"
     android:layout_below="@+id/txtHead"
     android:layout_marginTop="30dp" >
 </ListView>

 <ListView
     android:id="@+id/listViewPlane"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_alignLeft="@+id/txtHead"
     android:layout_below="@+id/txtHead"
     android:layout_marginTop="30dp" >
 </ListView>

 </RelativeLayout>

谢谢大家!

1 个答案:

答案 0 :(得分:0)

问题在于上下文,我给出了一个糟糕的上下文,这改变了listview文本的textcolor,第二个listView的正确上下文是:getBaseContext(),所以正确的适配器是:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_expandable_list_item_1, android.R.id.text1, intent.getStringArrayExtra("planos"));
希望这有助于其他人! :)