For example, ListView on my phone screen can display a total of 15 lines, if I select the first line, then the background color of the first line is changed, but the first 16 rows have been changed, solving ah, I change the background code as follows:
private View oldLinearLayout;
listView.setOnItemClickListener (new AdapterView.OnItemClickListener () {
@ Override
public void onItemClick (AdapterView paramAdapterView,
View paramView, int paramInt, long paramLong) {
if (beforeLinearLayout! = null) {
oldLinearLayout.setBackgroundDrawable (null);
}
paramView.setBackgroundColor (Color.GREEN);
oldLinearLayout = paramView;
}
});
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
getview time. . With a view object is re-used. . Add to judge the difference between what you can.
Reply:
How this judgment ah, solution
Reply:
Nobody knows yet

Reply:
http://bbs.csdn.net/topics/390431893
Reply:
That did not understand, my method does not work with you, above me wrong, if there is oldLinearLayout! = Null
Reply:
Record position and color contrast when taking the view position because this is the reason baseAdapter
Reply:
< br />You can write code
Reply:
Probably thinking:
1. Saved choose the current selection, then notify adapter to refresh the view
2 and then to fill the current View
based on the current selection in getView
/ / Adapter in
public void setSelected (int selected) {
this.selected = selected;
notifyDataSetChanged ();
}
/ /
When OnItemClickadapter.setSelected (position);
Reply:
this.selected what this is, ah, ah, I did not inherit Adapter, nor setSelected this method ah
This is what I wrote:
SimpleAdapter listItemAdapter = new SimpleAdapter (this, listdata, R.layout.list_salesck,
new String [] {"billdate", "state", "zhaiyao", "billname", "userfullname"},
new int [] {R.id.billdate, R.id.textView14, R.id.zhaiyao, R.id.billtype, R.id.userfullname});
listView.setAdapter (listItemAdapter);
listView.setOnItemClickListener (new AdapterView.OnItemClickListener () {
public void onItemClick (AdapterView paramAdapterView,
View paramView, int paramInt, long paramLong) {
if (oldLinearLayout! = null) {
oldLinearLayout.setBackgroundDrawable (null);
}
/ / Set the background color of a member of the Grey
paramView.setBackgroundColor (Color.GRAY);
nowClick = paramInt;
oldLinearLayout = paramView;
}
});
How I should add, ah, beg specific code
Reply:
/ / Adapter in
private int selected;
public void setSelected (int selected) {
this.selected = selected;
notifyDataSetChanged ();
}
/ / In getView determine whether the current position is selected in
if (position == selected) {
/ / Push background
} Else {
/ / Normal background
}
/ /
In the Activity page callback OnItemClickListeneradapter.setSelected (position);
Reply:
Where Adapter is, ah, ah, I do not have this class
Reply:
ListItem added directly to the background like a xml, the program to achieve too much trouble, the effect is not good.
Reply:
There plus background, tap disappeared
Reply:
ListView misplaced
rolling processWith ViewHolder to solve
For example:
getView ......
{
ViewHolder holder;
if (null == convertView) {
convertView = LayoutInflater.from (RewardActivity.this). inflate (
R.layout.reward_cions_item, null);
convertView = inflater.inflate (R.layout.reward_cions_item, null);
holder = new ViewHolder ();
holder.time = (TextView) convertView.findViewById (R.id.time);
convertView.setTag (holder);
} Else {
holder = (ViewHolder) convertView.getTag ();
}
holder.time.setText ("11");
return convertView;
}
class ViewHolder
{
TextView time;
......
}
Reply:
Do you want to tap the background does not disappear, it would see the upstairs bar :)
Reply:
1 Use ViewHolder mode initialization function is to avoid duplication of View, of course, a more appropriate approach is to do if the currently selected
within ViewHolder
Judgment, do background replacement,
2. LZ for Adapter adapter class is not very understanding, it is recommended to go to first understand BaseAdapter under this category, the above code in the adapter,
BaseAdapter is a specific instance of a subclass of the class, you should go to achieve this Adapter instance of the class, as a data source to provide data to the layout
I posted some of my code you can refer to solve this problem
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.ishow.funnymap.bean.Menu;
import com.ishow.funnymap.ui.R;
public class MenuGridViewAdapter extends BaseAdapter {
private Context context;
private List
OnItemClick Event
menuGridView.setOnItemClickListener (new OnItemClickListener () {
@ Override
public void onItemClick (AdapterView parent, View view,
int position, long id) {
onMenuSelectedListener.onMenuSelected (menuGridViewAdapter
. GetItem (position));
menuGridViewAdapter.setSelected (position);
/ / Dismiss ();
}
});
Reply:
Eyebrows_cs code is very clear, to learn the
No comments:
Post a Comment