简体   繁体   English

列表视图中的其他按钮

[英]Different Button in List view

I have two ArrayList namely "one" and "two" ["two" is always a sub-set of "one"], And i have a list view which is populating by Arraylist "one". 我有两个ArrayList,分别是“一个”和“两个” [“两个”始终是“一个”的子集],并且我有一个由Arraylist“一个”填充的列表视图。 Now am checking condition that if element of "two" is present in "one", then set ImageButton in list view and if not the set Button in list view. 现在正在检查条件,如果“一个”中存在“两个”元素,则在列表视图中设置ImageButton,如果没有,则在列表视图中设置ImageButton。 Below is my getView method. 下面是我的getView方法。 Any help or keywords will be appreciated. 任何帮助或关键字将不胜感激。

 @Override
public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    if (convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(context);
         //HERE HOW TO SWITCH TWO LAYOUTS.. 
        convertView = inflater.inflate(R.layout.invite_row, null);
        viewHolder = new ViewHolder();
        viewHolder.name = (TextView)convertView.findViewById(R.id.textView6);
        viewHolder.text = (TextView) convertView.findViewById(R.id.childTextView);
        viewHolder.button = (Button) convertView
                .findViewById(R.id.childButton);
        Typeface typeFace= Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Bold.ttf");
        viewHolder.name.setTypeface(typeFace);
        //      viewHolder.button.setBackgroundResource(R.drawable.invitebuttonbackground);
        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }


    final String temp = getItem(position);


   final String tempname = getItem(position);
    viewHolder.name.setText(tempname);
    viewHolder.button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (customListner != null) {
                customListner.onButtonClickListner(position, temp, tempname);

            }

        }
    });

    return convertView;
}

one thing you can do is 你可以做的一件事是

View convertView;
if (whatever condition) {
  convertView = inflater.inflate(R.layout.invite_row, null);
} else {
  convertView = inflater.inflate(R.layout.invite_row_two, null);
}

if you can post your layout , i will have clear undestanding of what you want to doing. 如果您可以发布您的布局,我将对您想做的事情一无所知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM