Android:ListView文字颜色不可见,我不希望它不可见 [英] Android: ListView text color is invisible and I don't want it invisible

查看:73
本文介绍了Android:ListView文字颜色不可见,我不希望它不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Layout上有两个ListView和一个EditText.我必须先显示一个,然后单击他的一个选项后,我必须显示另一个ListView.

I have two ListView and an EditText on my Layout. I have to show one first, and after clicked one of his options I have to show the other ListView.

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

All works fine, but the problem appears when I have to show the second ListView, I can't see the text of the options, I only can see the text when I press the option and it is pressed I can see the text in white (the same color of the background).

我不明白为什么会这样,因为我已经定义了ListView,就像第二个一样,但是其中一个以黑色显示文本,第二个以白色显示.除了它们的位置,我没有更改任何ListView属性.我把代码和xml文件放在可以帮助的地方,谢谢!

I don't understand why this happens, because I have the ListView one defined like the second, but one of them show the text in black and the second in white. I don't change any ListView property except the location of them. I put the code and the xml files if it could help, thanks!

这是我课程的一部分,所有与ListView s相关:

Here is a part of my class, all related to the ListViews:

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文件:

Here is the XML file of the layout:

<?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>

谢谢大家!

推荐答案

问题出在上下文上,我给的上下文不好,这改变了listview文本的textcolor,第二个listView的正确上下文是:getBaseContext (),因此正确的适配器是:

The problem was on the context, I was giving a bad context and this change the textcolor of the listview text, the correct context of the second listView is: getBaseContext(), so the correct adapter was:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_expandable_list_item_1, android.R.id.text1, intent.getStringArrayExtra("planos"));

希望这对其他人有所帮助! :)

Hope this help other people! :)

这篇关于Android:ListView文字颜色不可见,我不希望它不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆