change listview row background based on a choice from other activity:


Following my privious qustion that you can see here:

<a href="https://stackoverflow.com/questions/14345840/how-to-create-custom-listview-for-android-with-margins-between-2-elements" rel="nofollow">How to create custom listview for android with margins between 2 elements?</a>

I have made some progress due to the help I recived here. So my state right now is:

<a href="https://i.stack.imgur.com/yK5to.jpg" rel="nofollow">http://i.stack.imgur.com/yK5to.jpg</a>

pressing on the blue part of one of the tasks pops the following color plate activity:

<a href="https://i.stack.imgur.com/UWmIg.jpg" rel="nofollow">http://i.stack.imgur.com/UWmIg.jpg</a>

all the 5 colors here are buttons, what i need to do is to check what color was pressed and then change the background drawing of the task that opened the color plate activity.

Only that i don't understand how it's done, any suggestions? in the color plate activity i have an "setOnClickListener" function for each one of the buttons.

here is the java code for my list activity:

public class SkyGiraffeAppActivity extends Activity implements AdapterView.OnItemClickListener, View.OnClickListener { // All static variables static final String TAG = "SkyGiraffeAppActivity"; // XML node keys static final String KEY_TASK = "task"; // parent node static final String KEY_ID = "id"; static final String KEY_TITLE = "title"; static final String KEY_DATE = "date"; static final String KEY_TIME = "time"; static final String KEY_PRIORITY = "priority"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ListView list = new ListView(this); list.setDivider(null); list.setDividerHeight(0); setContentView(list); final ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>(); Log.e(TAG, "Created Array"); XMLParser parser = new XMLParser(); Log.e(TAG, "Getting xml from raw folder"); InputStream xml = getResources().openRawResource(R.raw.taskslists); // getting XML Log.e(TAG, "reading xml file to string"); String sxml = parser.readTextFile(xml); Log.e(TAG, "creating dom element from string"); Document doc = parser.getDomElement(sxml); // getting DOM element Log.e(TAG, "getting node list of all the elements"); NodeList nodeList = doc.getElementsByTagName(KEY_TASK); Log.e(TAG, "looping through all the elements"); for (int i = 0; i < nodeList.getLength(); i++) { // creating new HashMap HashMap<String, String> map = new HashMap<String, String>(); Element e = (Element) nodeList.item(i); Log.e(TAG, "element number: " + i + " added to hash map"); // adding each child node to HashMap key => value map.put(KEY_ID, parser.getValue(e, KEY_ID)); map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE)); map.put(KEY_DATE, parser.getValue(e, KEY_DATE)); map.put(KEY_TIME, parser.getValue(e, KEY_TIME)); map.put(KEY_PRIORITY, parser.getValue(e, KEY_PRIORITY)); // adding HashList to ArrayList menuItems.add(map); } // Adding menuItems to ListView ListAdapter adapter = new SimpleAdapter(this, menuItems, R.layout.row, new String[] { KEY_TITLE, KEY_DATE, KEY_TIME, KEY_PRIORITY}, new int[] { R.id.text_title, R.id.text_date, R.id.text_time ,R.id.image_priority}){ @Override public View getView(int position, View convertView, ViewGroup parent) { View row = super.getView(position, convertView, parent); View left = row.findViewById(R.id.bchangecolor); left.setTag(position); left.setOnClickListener(SkyGiraffeAppActivity.this); View right = row.findViewById(R.id.barrow); right.setTag(position); right.setOnClickListener(SkyGiraffeAppActivity.this); ImageView prioriy = (ImageView) row.findViewById(R.id.image_priority); Log.e(TAG, "pririty number: " + menuItems.get(position).get(KEY_PRIORITY)); int number = Integer.valueOf(menuItems.get(position).get(KEY_PRIORITY)); switch ( number ) { case 1: prioriy.setImageResource(R.drawable.priority_first); break; case 2: prioriy.setImageResource(R.drawable.priority_second); break; case 3: prioriy.setImageResource(R.drawable.priority_third); break; case 4: prioriy.setImageResource(R.drawable.priority_fourth); break; case 5: prioriy.setImageResource(R.drawable.priority_fifth); break; default: prioriy.setImageResource(R.drawable.priority_first); } return row; } }; list.setAdapter(adapter); list.setOnItemClickListener(this); } public void onClick(View v) { switch(v.getId()) { case R.id.bchangecolor: Log.e(TAG, "pressed the color change button on" + v.getId()); startActivity(new Intent(getApplicationContext(),TaskColorChangeActivity.class)); break; case R.id.barrow: Log.e(TAG, "pressed the arrow button on" + v.getId()); Intent intent = createIntentwithExtra(v); startActivity(intent); break; default: break; } } public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Log.e(TAG, "pressed the row itself" + v.getId()); Intent intent = createIntentwithExtra(v); startActivity(intent); } public Intent createIntentwithExtra(View v) { Intent intent = new Intent(getApplicationContext(), SingleMenuItemActivity.class); String title = ((TextView) v.findViewById(R.id.text_title)).getText().toString(); String date = ((TextView) v.findViewById(R.id.text_date)).getText().toString(); String time = ((TextView) v.findViewById(R.id.text_time)).getText().toString(); intent.putExtra(KEY_TITLE, title); intent.putExtra(KEY_DATE, date); intent.putExtra(KEY_TIME, time); return intent; }}

and my color plate activity:

public class TaskColorChangeActivity extends Activity { static final String TAG = "TaskColorChangeActivity"; Button bBlue, bGreen, bYellow, bOrange, bRed; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.colorplate); bBlue = (Button) findViewById(R.id.bblue); bGreen = (Button) findViewById(R.id.bgreen); bYellow = (Button) findViewById(R.id.byellow); bOrange = (Button) findViewById(R.id.borange); bRed = (Button) findViewById(R.id.bred); bBlue.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { } }); bGreen.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { } }); bYellow.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { } }); bOrange.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { } }); bRed.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { } }); }}

it would be nice if someone with permissions changed the links to the actual images. Thanks.


You can return some data from you activity to your parent activity

( <a href="https://stackoverflow.com/questions/2497205/how-to-return-a-result-startactivityforresult-from-a-tabhost-activity" rel="nofollow">How to return a result (startActivityForResult) from a TabHost Activity?</a> )

You can return what color you've choosen and regarding this data you can do whatever you want.


  • How to get Images from Internet and past it in a ListView?
  • SQLiteException using WHERE “ +KEY_Date+”='“+date+”'\" [duplicate]
  • Create pagination using while loop
  • How to save state of changed ImageView in Listview row, after it' has disappeared from screen?
  • Why java statement evaluation is happening like these ?
  • How does Skobbler prioritize which POIs to show?
  • RxJava,Retrofit Error :Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
  • onActivityResult() not called after startActivityForResult() with Intent.ACTION_GET_CONTENT
  • Store additional information during registration with Firebase in Android
  • Shuffling an Array in Android
  • Where are files stored on an Android emulator?
  • using a UILocalNotification to play a sound that's not in the app bundle
  • Multiple storyboards: should I use a singleton pattern to cache them?
  • android-How to enable cache or buffering when videoView have downloaded a video
  • “[CALayer release]: message sent to deallocated instance” when dismissing modal view controller
  • Requiring gem in Rails 3 Controller failing with “Constant Missing”
  • OnItemSelectedListener for Spinner that was added programmatically does not trigger
  • How to define log4j2 path by application.properties?
  • How to send params in url query_string in Symfony?
  • Listview - list item selection and initial setting (custom made items)
  • UIScrollView setContentOffset: animated: not working
  • Log4j cannot find properties file in a simple application
  • Installing libCurl - ruby 1.9.3 .. rails 3.2.12 .. Windows
  • How to create a new Bundle object?
  • How to get listview position?
  • Connect .sks to skscene.h
  • How to test if a URL from an Eclipse bundle is a directory?
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Display issues when we change from one jquery mobile page to another in firefox
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Release, debug version and Authorization Google?
  • To display the title for the current loaction in map in iphone
  • Cannot Parse HTML Data Using Android / JSOUP
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • trying to dynamically update Highchart column chart but series undefined
  • Hits per day in Google Big Query
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]