Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android listview中的滚动问题_Android_Listview - Fatal编程技术网

Android listview中的滚动问题

Android listview中的滚动问题,android,listview,Android,Listview,//从片段填充ArrayList gridmodel = new TypeTruckPogo("Truck 14 wheel",-1,false); list.add(gridmodel); gridmodel = new TypeTruckPogo("Truck 16 wheel",-1,false); list.add(gridmodel); final TypeOfTruckAdapter truckAdapter=new

//从片段填充ArrayList

gridmodel = new TypeTruckPogo("Truck 14 wheel",-1,false);
        list.add(gridmodel);
        gridmodel = new TypeTruckPogo("Truck 16 wheel",-1,false);
        list.add(gridmodel);

        final TypeOfTruckAdapter truckAdapter=new TypeOfTruckAdapter(context, list);
        truckListView.setAdapter(truckAdapter);
//我的POGO课

public class TypeTruckPogo{
    String typeOfTruckName;
    int nmbrOfTruck;
    boolean isEditTextVisiable;

    public TypeTruckPogo(String typeOfTruckName,int nmbrOfTruck,boolean isEditTextVisiable){
        this.typeOfTruckName=typeOfTruckName;
        this.nmbrOfTruck=nmbrOfTruck;
        this.isEditTextVisiable=isEditTextVisiable;
    }

    public String getTypeOfTruckName() {
        return typeOfTruckName;
    }

    public String setTypeOfTruckName(String typeOfTruckName) {
        this.typeOfTruckName = typeOfTruckName;
        return typeOfTruckName;
    }

    public int getNmbrOfTruck() {
        return nmbrOfTruck;
    }

    public Integer setNmbrOfTruck(int nmbrOfTruck) {
        this.nmbrOfTruck = nmbrOfTruck;
        return nmbrOfTruck;
    }

    public boolean isEditTextVisiable() {
        return isEditTextVisiable;
    }

    public Boolean setIsEditTextVisiable(boolean isEditTextVisiable) {
        this.isEditTextVisiable = isEditTextVisiable;
        return isEditTextVisiable;
    }
}
//我的Adapter类,这个类在列表中有20个项目,第一次它显示8个项目,当用户按单行时editText变为可见,如果用户按两次相同的位置,editText变为不可侵犯,但问题是当用户点击任何位置时(假设他点击了位置0)然后editText是可见的,但当我向下滚动时,其他editText也会在位置8或15的某个时间可见。感谢您的帮助!!!!单行包含textView和editText

public class TypeOfTruckAdapter extends BaseAdapter{
List<TypeTruckPogo> list;
Context context;
LayoutInflater inflater;
public String[] Current;
TypeTruckPogo typeTruckPogo;
public static HashMap<Integer,String> truckHashMap=new HashMap<Integer,String>();
public TypeOfTruckAdapter( Context context,List<TypeTruckPogo> list) {
    this.list = list;
    this.context = context;
    for(int i=0;i<list.size();i++)
    {
        truckHashMap.put(i,"");
    }
}
@Override
public int getCount() {
    // TODO Auto-generated method stub
    return list.size();
}

@Override
public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}



class Viewholder{
    TextView name;
    EditText nmbrOfTruck;
    int ref;

    Viewholder(View view) {

        name = (TextView) view.findViewById(R.id.textView1);
        nmbrOfTruck = (EditText) view.findViewById(R.id.et_nmbr_of_truck_id);
    }

}
@Override
public View getView(final int position, View convertView,  ViewGroup parent) {
    final Viewholder holder;
    typeTruckPogo = list.get(position);
    if(convertView==null){
        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        convertView = inflater.inflate(R.layout.single_row_for_type_of_truck, parent, false);
        holder = new Viewholder(convertView);
        convertView.setTag(holder);
    }else{
        holder = (Viewholder)convertView.getTag();
    }
    // For position zero i have to set the text color to blue color,else dark gray color
    if(position==0){
        holder.name.setTextColor(context.getResources().getColor(R.color.blue_color));
    }else{
        holder.name.setTextColor(context.getResources().getColor(R.color.darkgray));
    }
    // setting the name on the textview
    holder.name.setText(list.get(position).getTypeOfTruckName());
    //setting the tag on edittext
    holder.nmbrOfTruck.setTag(position);
    //setting the viewholder position
    holder.ref = position;

   // clicking on listview making edittext to appear (initially edittext is invisiable)
    // if edittext is visiable make it invisiable and if it is invisiable make it visiable
    convertView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (v.findViewById(R.id.et_nmbr_of_truck_id).getVisibility() == View.VISIBLE) {
                v.findViewById(R.id.et_nmbr_of_truck_id).setVisibility(View.INVISIBLE);
            } else {
                v.findViewById(R.id.et_nmbr_of_truck_id).setVisibility(View.VISIBLE);
            }

        }
    });
    // if user write on editText save the input by the user in specified position
    //truckHashMap is hashmap where I saving the position as a key and value as the user Input

    holder.nmbrOfTruck.addTextChangedListener(new TextWatcher() {

        public void onTextChanged(CharSequence s, int start,
                                  int before, int count) {

        }

        public void beforeTextChanged(CharSequence s, int start,
                                      int count, int after) {
            // TODO Auto-generated method stub

        }

        public void afterTextChanged(Editable s) {
            Current = new String[holder.ref];

            truckHashMap.put(position, s.toString().trim());
        }
    });
    // Setting the User Input at specified Position
    holder.nmbrOfTruck.setText(truckHashMap.get(position));

    Config.colorFont(context, null, holder.name, null);
    return convertView;
}
公共类TypeOfTruckAdapter扩展了BaseAdapter{
名单;
语境;
充气机;
公共字符串[]当前;
类型TruckPogo类型TruckPogo;
public static HashMap truckHashMap=new HashMap();
公共TypeOfTruckAdapter(上下文,列表){
this.list=列表;
this.context=上下文;

对于(int i=0;i您必须使用else语句来设置适配器中的默认文本颜色:

...
if(position==0){
            holder.name.setTextColor(context.getResources().getColor(R.color.blue_color));
        } else {
          // here set your default text color black for example
          holder.name.setTextColor(context.getResources().getColor(R.color.black_color));
}
...

希望有帮助!

您必须使用else语句在适配器中设置默认文本颜色:

...
if(position==0){
            holder.name.setTextColor(context.getResources().getColor(R.color.blue_color));
        } else {
          // here set your default text color black for example
          holder.name.setTextColor(context.getResources().getColor(R.color.black_color));
}
...

希望有帮助!

您的
其他情况如何

    if(position==0)
    {
              holder.name.setTextColor(context.getResources().getColor(R.color.blue_color));
    } else {

    // Calling when if Condition not Satisfied .
             holder.name.setTextColor(context.getResources().getColor("Your_Color"));
            }

您的
其他
状况在哪里

    if(position==0)
    {
              holder.name.setTextColor(context.getResources().getColor(R.color.blue_color));
    } else {

    // Calling when if Condition not Satisfied .
             holder.name.setTextColor(context.getResources().getColor("Your_Color"));
            }

position==0
在滚动listview时每次都会更改,但如果使用与模型类相关的索引并基于该索引放置条件,则每次滚动listview时都会更改
position==0
,但如果使用与模型类相关的索引并放置条件,则会有效基于该索引的条件,将有效您已投票但未接受。接受是指在我的答案上单击投票箭头下方的绿色勾选。谢谢。现在其他人将知道我的答案对您有帮助。让我们一起来。滚动时我还有一个问题,我已更新BaseAdapter的代码请创建新问题,因为s是不同的情况,给mi一个链接,我会回答你。问候。你投了票,但没有接受。接受是在我的答案上单击投票箭头下方的绿色勾选时。谢谢。现在其他人会知道我的答案对你有帮助。让我们一起来。滚动时我还有一个问题,我已经更新了baseAdapterPlease crea的代码新问题,因为这是不同的情况,给我一个链接,我会回答你。问候。