2013年10月17日星期四

[Android] ListView touch , the background color , item will change , how to do ?

Now I want to achieve such an effect . Below is a list of ListView , when the touch an item , the background color will be green ,

ImageView will change the icon , TextView text will turn red when the finger is removed, will restore the original state.




If you just get some better change the background color , set the selector for the ListView on it, but there is also to change the contents of the controls on the Item more trouble , I thought using onTouch () event can get
But after setting , ListView click event itself will be masked. Depressed ......


------ Solution ------------------------------------ --------
seemingly use this property ?
android: drawSelectorOnTop = "false"
------ Solution ---------------------------- ----------------
android: cacheColorHint = "# 00000000"
/>
Or:
code states listview.setCacheColorHint (0);

------ Solution ------------------------------------ --------
mListView.setOnItemClickListener (new OnItemClickListener () {

public void onItemClick (AdapterView arg0, View v,
int position, long arg3) {
v.setBackgroundColor (Color.BLUE) ;
}
}
------ Solution ----------------------------------- ---------
listview.setOnItemClickListener ();
------ Solution ---------------------- ----------------------
set selector is not enough to modify the ListView adapter, in getview () is taken to deal with effects processing control object .
------ Solution ---------------------------------------- ----
can listen OnTouchListener listview

list.setOnTouchListener (new OnTouchListener () {

@ Override
public boolean onTouch (View v, MotionEvent event) {
/ / TODO Auto-generated method stub
switch (event.getAction ()) {
case MotionEvent.ACTION_DOWN:
Toast.makeText (ListViewTween.this, "down", 1000). show ();
break;

default:
break;
}
return false;
}
});
Then you put in that Case View stronger inside into listview, and then change its properties can be !
------ Solution ---------------------------------------- ----
this do not know if . .
------ eference --------------------------------------- < br> 1 , 2nd did not understand what I mean , ah, 3rd Floor understand, but this is not possible , OnItemClickListener is clicked state ,
I need is a difference when pressed , but still thank you for your answer
------ eference --------------------- ------------------
online ...
------ eference -------------- -------------------------

this
------ eference ------ ---------------------------------
Oh, I did not read all , did not pay attention to hand when leave to restore the original state
------ eference ------------------------------------ ---
landlord, you also unfair to the bar, I was the first to say listen OnTouch events , but also help you to press events are somehow, I had five points, 11 F, 11 points ?
------ eference --------------------------------------- < br> next time you fill
------ eference -------------------------------- -------
great !

没有评论:

发表评论