列表视图风格每一行 [英] Listview style Each Row
问题描述
这是我的自定义适配器code(THE code在棕褐色)时,最初当我向下滚动,再滚动列表中变化的所有行列表建立适当的余量应用到有效的项目20留下的余量我在做什么错了,请尽快答复
@覆盖
公共查看getView(最终诠释的立场,观点convertView,父母的ViewGroup){ 最后ViewHolder持有人;
//获取数据
最后ViewMovieDetailsModel_ViewComments电影=的getItem(位置); 如果(convertView == NULL)
{
convertView = View.inflate(背景下,R.layout.comment_row,NULL);
持有人=新ViewHolder(); //获取手柄 holder.comments_linearLayout =(的LinearLayout)convertView.findViewById(R.id.comments_linearLayout);
holder.commenter_textView =(TextView中)convertView.findViewById(R.id.comment_row_commenter);
holder.commented_on_textView =(TextView中)convertView.findViewById(R.id.comment_row_comment_time);
holder.comment_text_textView =(TextView中)convertView.findViewById(R.id.comment_row_comment_text);
holder.reply_button =(按钮)convertView.findViewById(R.id.comment_row_reply_button); convertView.setTag(保持器);
}
其他
{
支架=(ViewHolder)convertView.getTag();
} 如果(电影!= NULL)
{
如果(((movies.getParent_comment_id())的toString()等于(空))及。&放大器; session.isLoggedIn()== TRUE){
holder.reply_button.setVisibility(View.VISIBLE);
}其他{
holder.reply_button.setVisibility(View.INVISIBLE);
}
`如果(!((movies.getParent_comment_id())。的toString()。等于(空)))
{的LayoutParams PARAMS =新的LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
params.setMargins(20,0,0,0);
holder.comments_linearLayout.setLayoutParams(PARAMS);
}`
holder.commenter_textView.setText(movies.getUsername_commentor()); holder.commenter_textView.setTag(movies.getUser_id_commentor()); 返回convertView;
}
由于您在设置边距(棕色字体)'如果'语句:
如果(电影!= NULL)
只是把它拿出来的这个,如果块(例如把它刚刚返回点前)
现在这个code可能没有在第一个视图加载执行,因为影片为空。当getView被称为第二次,这部电影不为空,且marigin设置根据你的'棕'code。
如果这不是解决办法 - if语句的条件是不正确的(一个是在第一个Brown行)也许里面。所以..你自己的逻辑prevents的marigins要设置为你想要的:)
请让我知道,如果它帮助。
this is the code in my custom adapter (THE CODE IN BROWN COLOR) when initially list is build proper margin is applied to valid items when i scroll down and again scroll up all the rows in list shifts the margin left by 20 what i'm doing wrong please reply soon
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
// getting data
final ViewMovieDetailsModel_ViewComments movies = getItem(position);
if (convertView == null)
{
convertView = View.inflate(context, R.layout.comment_row, null);
holder = new ViewHolder();
//getting handles
holder.comments_linearLayout = (LinearLayout) convertView.findViewById(R.id.comments_linearLayout);
holder.commenter_textView = (TextView) convertView.findViewById(R.id.comment_row_commenter);
holder.commented_on_textView = (TextView) convertView.findViewById(R.id.comment_row_comment_time);
holder.comment_text_textView = (TextView) convertView.findViewById(R.id.comment_row_comment_text);
holder.reply_button = (Button) convertView.findViewById(R.id.comment_row_reply_button);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder)convertView.getTag();
}
if (movies != null)
{
if (((movies.getParent_comment_id()).toString().equals("null")) && session.isLoggedIn()==true) {
holder.reply_button.setVisibility(View.VISIBLE);
}else{
holder.reply_button.setVisibility(View.INVISIBLE);
}
`if (!((movies.getParent_comment_id()).toString().equals("null")))
{
LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
params.setMargins(20, 0, 0, 0);
holder.comments_linearLayout.setLayoutParams(params);
}`
holder.commenter_textView.setText(movies.getUsername_commentor());
holder.commenter_textView.setTag(movies.getUser_id_commentor());
return convertView;
}
because you are setting margins (the brown font) in 'if' statement:
if (movies != null)
just take it out of this if block (for example put it just before the return point)
Right now this code is probably not executed at the first view load, since the movie is null. When the getView is called second time, the movie is not null, and the marigin is set according to your 'brown' code.
if this is not the solution - maybe the inside if statement condition is not true (the one that is in first 'brown' row). so.. your own logic prevents the marigins to be set as you want :)
Please let me know if it helps.
这篇关于列表视图风格每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!