1

Can anyone please help me out. I'm having problems changing my array list properties. I am more familiar with changing properties via the XML file. Here is my code:

package com.example.examproject;

import java.util.Random;

import android.os.Bundle;
import android.app.ListActivity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.content.Intent;

public class Menu_Lists extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         String[] myAttractions = new String[2];
         myAttractions[0] = "Grocery List";
         myAttractions[1] = "Go Back";

        setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, myAttractions));
    }

    protected void onListItemClick(ListView l, View v, int position, long id) {
        switch(position) {
        case 0: {
            startActivity(new Intent(Menu_Lists.this, MainActivity.class));
            break;
        } 
        default: {
            startActivity(new Intent(Menu_Lists.this, MainActivity.class));
        } 
        } 
    }

    @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;
    }

}

What I would like to do is to change the background color. That's my main goal. I would also like each option to change color whenever the user hovers over a specific option.

Please go easy with the terminologies as well. I am still a beginner with Android SDK.

Thanks in advance.

Gareth
  • 11
  • 2
  • have you tried anything yet? the code you pasted does not provide any specific problem... Check-out that answer here: http://stackoverflow.com/a/15439656/944070 for XML formating. If you want to do that via code you should look for a custom adapter – madlymad Apr 05 '14 at 13:20
  • I pasted the code as I thought it would be beneficial to solving my problem. Can I link an XML file to the java class? From my knowledge, if you use ListActivity you cannot use setContentView(). Is there any solution to this? All I want to do is to set the actual background (not the background of the list) to a different color. – Gareth Apr 05 '14 at 14:32
  • P.S Thanks for aligning my code. I uploaded the code via my mobile – Gareth Apr 05 '14 at 14:35
  • I cannot really get your problem so cannot suggest any answer. But as far as `setContentView()` of course you can use it check out the 3rd snippet here : http://developer.android.com/reference/android/app/ListActivity.html get through whole tutorial it may be really helpful to your problem. – madlymad Apr 05 '14 at 18:34
  • I will check your link. If I still experience difficulties then I will upload an image of the problem – Gareth Apr 06 '14 at 09:22

0 Answers0