我必须指出用户一旦用户点击保存按钮,这个编辑文本是留空的标题下,通过设置背景颜色的标题和编辑文本,但它不工作。我已经找过了,但没有得到任何解决方案。请帮帮忙。提前谢谢。
下面是我用来设置edittext的背景颜色的代码,但它给其他子对象中的其他edittext着色。
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<OpeningStockInsertDataGetterSetter> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<OpeningStockInsertDataGetterSetter, List<StockGetterSetter>> _listDataChild;
public ExpandableListAdapter(Context context, List<OpeningStockInsertDataGetterSetter> listDataHeader,
HashMap<OpeningStockInsertDataGetterSetter, List<StockGetterSetter>> listChildData) {
this._context = context;
this._listDataHeader = listDataHeader;
this._listDataChild = listChildData;
}
@Override
public Object getChild(int groupPosition, int childPosititon) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.get(childPosititon);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@SuppressLint("NewApi")
@Override
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final StockGetterSetter childText = (StockGetterSetter) getChild(groupPosition, childPosition);
ViewHolder holder=null;
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
holder=new ViewHolder();
holder.etaspermcn=(TextView) convertView.findViewById(R.id.etAs_Per);
holder.etopnstkcldrm=(EditText) convertView.findViewById(R.id.etOpening_Stock);
holder.etopnstkmcndf=(EditText) convertView.findViewById(R.id.etOpening_Stock_Mc);
if(openmdfFlag){
holder.openmccaindf_layout.setVisibility(View.VISIBLE);
}
convertView.setTag(holder);
}
else{
holder = (ViewHolder) convertView.getTag();
}
holder.etopnstkcldrm.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
showKeyboardWithAnimation();
}
if (!hasFocus) {
hide();
final int position = v.getId();
final EditText Caption = (EditText) v;
String value1 = Caption.getText().toString();
if (value1.equals("")) {
_listDataChild
.get(listDataHeader.get(groupPosition))
.get(position).setOpen_stock_cold_room("");
} else {
_listDataChild
.get(listDataHeader.get(groupPosition))
.get(position).setOpen_stock_cold_room(value1);
}
}
}
});
holder.etopnstkmcndf.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
showKeyboardWithAnimation();
}
if (!hasFocus) {
hide();
final int position = v.getId();
final EditText Caption = (EditText) v;
String value1 = Caption.getText().toString();
if (value1.equals("")) {
_listDataChild
.get(listDataHeader.get(groupPosition))
.get(position).setOpen_stock_mccaindf("");
} else {
_listDataChild
.get(listDataHeader.get(groupPosition))
.get(position).setOpen_stock_mccaindf(value1);
}
}
}
});
holder.ettotalfacmcndf.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
showKeyboardWithAnimation();
}
if (!hasFocus) {
hide();
final int position = v.getId();
final EditText Caption = (EditText) v;
String value1 = Caption.getText().toString();
if (value1.equals("")) {
_listDataChild
.get(listDataHeader.get(groupPosition))
.get(position).setTotalfacing_mccaindf("");
} else {
_listDataChild
.get(listDataHeader.get(groupPosition))
.get(position).setTotalfacing_mccaindf(value1);
}
}
}
});
holder.etopnstkcldrm.setId(childPosition);
holder.etopnstkmcndf.setId(childPosition);
holder.ettotalfacmcndf.setId(childPosition);
holder.etaspermcn.setText(childText.getAs_per());
holder.etopnstkcldrm.setText(childText.getOpen_stock_co());
holder.etopnstkmcndf.setText(childText.getOpen_stock_mc());
holder.ettotalfacmcndf.setText(childText.getTotalfacing_mc());
_listDataChild
.get(listDataHeader.get(groupPosition))
.get(childPosition).setSku_cd(childText.getSku_cd());
TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
txtListChild.setText(childText.getSku());
if(!checkflag){
if(holder.etopnstkcldrm.getText().toString().equals("")){
holder.etopnstkcldrm.setBackgroundColor(getResources().getColor(R.color.red));
}
else
holder.etopnstkcldrm.setBackgroundColor(getResources().getColor(R.color.white));
if(holder.etopnstkmcndf.getText().toString().equals("")){
holder.etopnstkmcndf.setBackgroundColor(getResources().getColor(R.color.red));
}
else
holder.etopnstkcldrm.setBackgroundColor(getResources().getColor(R.color.white));
if(holder.ettotalfacmcndf.getText().toString().equals("")){
holder.ettotalfacmcndf.setBackgroundColor(getResources().getColor(R.color.red));
}
else
holder.etopnstkcldrm.setBackgroundColor(getResources().getColor(R.color.white));
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return this._listDataChild.get(this._listDataHeader.get(groupPosition))
.size();
}
@Override
public Object getGroup(int groupPosition) {
return this._listDataHeader.get(groupPosition);
}
@Override
public int getGroupCount() {
return this._listDataHeader.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
OpeningStockInsertDataGetterSetter headerTitle = (OpeningStockInsertDataGetterSetter) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
//final int position = convertView.getId();
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle.getBrand());
if(!checkflag){
if(checkHeaderArray.contains(groupPosition)){
lblListHeader.setBackgroundColor(getResources().getColor(R.color.red));
}
}
//convertView.setId(groupPosition);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
public class ViewHolder{
EditText etopnstkcldrm,etopnstkmcndf,ettotalfacmcndf;
TextView etaspermcn;
LinearLayout openmccaindf_layout;
}在设置一个标题的背景时,滚动背景也设置为许多其他标题。
发布于 2015-08-13 14:46:04
使用setTag和getTag convertView您的问题将会得到解决。
发布于 2015-08-17 18:31:31
最后,我通过将特定视图设置为红色,将所有其他视图设置为白色,解决了这个问题。为此,我检查了空的edittext,如果它设置为红色或白色。在滚动时也能正常工作。
https://stackoverflow.com/questions/31980179
复制相似问题