Following my privious qustion that you can see here:
How to create custom listview for android with margins between 2 elements?
I have made some progress due to the help I recived here. So my state right now is:
https://i.stack.imgur.com/yK5to.jpg
pressing on the blue part of one of the tasks pops the following color plate activity:
https://i.stack.imgur.com/UWmIg.jpg
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.