更改列表视图行背景的基础上,从其他活动的选择: [英] change listview row background based on a choice from other activity:

查看:104
本文介绍了更改列表视图行背景的基础上,从其他活动的选择:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面我privious qustion,你可以在这里看到:

Following my privious qustion that you can see here:

<一个href="http://stackoverflow.com/questions/14345840/how-to-create-custom-listview-for-android-with-margins-between-2-elements">How为机器人与2单元之间的利润率创建自定义列表视图?

我已经取得了一些进展,由于帮助我recived这里。 所以,我的状态现在的问题是:

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

http://i.stack.imgur.com/yK5to.jpg

pressing上的任务之一的蓝色部分弹出下面的彩钢板活动:

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

http://i.stack.imgur.com/UWmIg.jpg

所有的5种颜色这里有按钮,我需要做的是检查什么颜色呈 pressed,然后更改打开该彩钢板活动任务的背景图。

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.

只是我不明白它是如何做的,有什么建​​议? 在彩钢板活动我有一个setOnClickListener功能按钮中的每一个。

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.

下面是java code我的列表活动:

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

和我的彩钢板活动:

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

(<一href="http://stackoverflow.com/questions/2497205/how-to-return-a-result-startactivityforresult-from-a-tabhost-activity">How从TabHost活动返回结果(startActivityForResult)?)

您可以返回什么颜色你choosen以及有关这些数据,你可以做任何你想要的。

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

这篇关于更改列表视图行背景的基础上,从其他活动的选择:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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