Change background color of TextView

2

I would like to know how to change a background of a text view , as I am pulling the data from the parse.com site, but I am not can do, what I'm trying is this:

          public class Pizzarias extends ActionBarActivity {

// Declare Variables
Boolean bColorStatus = true;
TextView status;
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ListViewAdapterPizzarias adapter;
private List<WorldPopulation> worldpopulationlist = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pizzarias);


new RemoteDataTask().execute();
//getSupportActionBar().setDisplayHomeAsUpEnabled(true);

status = (TextView) findViewById(R.id.status);
// status.setBackgroundColor(Color.BLUE);


}

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

//Os metodos abaixo são para mostrar o icone do aplicativo na action bar
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setLogo(R.drawable.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);

return true;
}


/*@Override
public boolean onOptionsItemSelected(MenuItem item) {
onBackPressed();
return true;
}*/


//RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
    super.onPreExecute();
    // Create a progressdialog
    mProgressDialog = new ProgressDialog(Pizzarias.this);
    // Set progressdialog title
    mProgressDialog.setTitle("Carregando Pizzarias");
    // Set progressdialog message
    mProgressDialog.setMessage("Aguarde...");
    mProgressDialog.setIndeterminate(false);
    // Show progressdialog
    mProgressDialog.show();
}

@Override
protected Void doInBackground(Void... params) {
    // Create the array
    worldpopulationlist = new ArrayList<WorldPopulation>();
    try {
        // Locate the class table named "Country" in Parse.com
        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                "GerenciarPizzariasPatos");
        // Locate the column named "ranknum" in Parse.com and order list
        // by ascending,


//here is the implementation to search for the word "closed" and change the background color.
        query.whereStartsWith ( "status" , "fechado" );
        ob = query.find();
        if(query.equals("fechado")){
            status.setTextColor(getResources().getColor(R.color.red));
            bColorStatus = false;
        }
        else {
            status.setTextColor(getResources().getColor(R.color.green));
            bColorStatus = true;
        }

        query.orderByAscending("nome");
        query.equals("status");
        ob = query.find();
        for (ParseObject country : ob) {
            WorldPopulation map = new WorldPopulation();
            map.setNome((String) country.get("nome"));
            map.setEndereco((String) country.get("endereco"));
            map.setTelefone((String) country.get("telefone"));
            map.setStatus((String) country.get("status"));
            worldpopulationlist.add(map);
        }
    } catch (ParseException e) {
        Log.e("Error", e.getMessage());
        e.printStackTrace();
    }
    return null;
}

@Override
protected void onPostExecute(Void result) {
    // Locate the listview in listview_main.xml
    listview = (ListView) findViewById(R.id.listviewpizzarias);
    // Pass the results into ListViewAdapter.java
    adapter = new ListViewAdapterPizzarias(Pizzarias.this,
            worldpopulationlist);
    // Binds the Adapter to the ListView
    listview.setAdapter(adapter);
    // Close the progressdialog
    mProgressDialog.dismiss();
}
}

Could someone help?

    
asked by anonymous 30.04.2015 / 14:03

1 answer

1
txt.setBackgroundColor(Color.parseColor("#BABABA")); 

or

txt.setBackgroundColor(Color.RED); // set default RED color as background color
    
30.04.2015 / 21:45