我必须在用户点击保存按钮后指示用户,此编辑文本在此标题下保留为空,方法是将背景颜色设置为该标题和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;
}
在设置一个标题的背景时,滚动背景也设置为许多其他标题。
答案 0 :(得分:0)
使用setTag和getTag进行转换,您的问题将得到解决。
答案 1 :(得分:0)
最后,我通过将特定视图设置为红色并将所有其他视图设置为白色来解决问题。为此我检查了空的edittext,如果它被设置为红色,则为白色。在滚动时也能正常工作。