You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.9 KiB
70 lines
1.9 KiB
package com.example.register.adapter;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Color;
|
|
import android.util.Log;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.BaseAdapter;
|
|
import android.widget.TextView;
|
|
|
|
import com.example.register.R;
|
|
|
|
import java.util.List;
|
|
|
|
public class Adapter extends BaseAdapter {
|
|
private List<String> productCategory;
|
|
private LayoutInflater layoutInflater;
|
|
private int selectionPosition = -1;
|
|
|
|
public Adapter(List<String> productCategory, Context context) {
|
|
this.productCategory = productCategory;
|
|
this.layoutInflater = LayoutInflater.from(context);
|
|
}
|
|
|
|
@Override
|
|
public int getCount() {
|
|
return productCategory.size();
|
|
}
|
|
|
|
@Override
|
|
public Object getItem(int position) {
|
|
return productCategory.get(position);
|
|
}
|
|
|
|
@Override
|
|
public long getItemId(int position) {
|
|
return position;
|
|
}
|
|
|
|
@Override
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
ViewHolder viewHolder = null;
|
|
if (convertView == null) {
|
|
viewHolder = new ViewHolder();
|
|
convertView = layoutInflater.inflate(R.layout.category_list_item, null);
|
|
Log.i("adapts", "getView: " + convertView);
|
|
viewHolder.tv = convertView.findViewById(R.id.categor_titles);
|
|
convertView.setTag(viewHolder);
|
|
} else {
|
|
viewHolder = (ViewHolder) convertView.getTag();
|
|
}
|
|
viewHolder.tv.setText(productCategory.get(position));
|
|
if (selectionPosition == position) {
|
|
viewHolder.tv.setBackgroundColor(Color.YELLOW);
|
|
} else {
|
|
viewHolder.tv.setBackgroundColor(Color.WHITE);
|
|
}
|
|
return convertView;
|
|
}
|
|
|
|
public void setSelectedPosition(int position) {
|
|
this.selectionPosition = position;
|
|
}
|
|
|
|
class ViewHolder {
|
|
TextView tv;
|
|
}
|
|
}
|