0

私はonClickこのようなものを持っています:

public void onClick(View v) {
    updateTable(v.getId()); //All ID's are Int, e.g. id=400
}

public void updateTable(int intID) {
    TextView itemToChange = (TextView) findViewById(intID);
    itemToChange.setTextColor(Color.RED);
}

だから私はTextView(id = 400)のIDを持っていますどうすればそれの色を変えることができますか?

私がやろうとしていることはfindViewById(int)、どのように渡しvupdateTable()使用することができるかです

((TextView) v).setTextColor(Color.RED);

何か案は?

4

1 に答える 1

1

If you want to pass v into your function, then why don't you just pass v?

public void updateTable(View view)

You'll still be able to get the id back out with the same function call. Now you don't even need to do findViewById because you already have a handle on the view. Just cast it to a textView.

TextView colorChanger = (TextView) view;
于 2012-06-08T17:57:21.797 に答える