Android列表视图背景颜色onitemclick

时间:2015-03-10 09:22:25

标签: android listview adapter

我在项目点击时将按钮的可见性设置为VISIBLE或GONE。问题是当我第一次点击某个项目时,listview正在重新加载。而下一次它不是。

这就是为什么我无法在第一次点击项目时修复背景颜色,但我需要在项目上单击两次以修复背景颜色。下一次通过在我的" onItemClick"中强制背景颜色来修复背景颜色。功能

当我删除" setvisible"在clicklistener上,问题消失了。我想知道为什么我的观点正在重新加载?我可以通过修复我的适配器上的日志来看到这一点。

public class MallListAdapter extends BaseAdapter
{
    ArrayList<ArrayList<String>> data_list;
    Context context;

    public MallListAdapter(Context c, ArrayList<ArrayList<String>> data)
    {
        super();
        data_list = data;
        context = c;
    }

    @Override
    public View getView(int pos, View view, ViewGroup viewgroup) 
    {
        Log.d(Config.DebugTAG,"Get view");
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.simple_listview_row, null);        
        TextView tv1 = (TextView) view.findViewById(R.id.state_txt);

        tv1.setText(data_list.get(pos).get(3));

        TextView tv2 = (TextView) view.findViewById(R.id.shop_name);
        tv2.setText(data_list.get(pos).get(0));

        TextView tv3 = (TextView) view.findViewById(R.id.last_date);
        String tokenDate[] = data_list.get(pos).get(1).split("/");
        String date_t = tokenDate[1]+"/"+tokenDate[2];
        tv3.setText(date_t);

        return view;
    }

    @Override
    public int getCount() 
    {
        return data_list.size();
    }

    @Override
    public Object getItem(int pos) 
    {
        return pos;
    }

    @Override
    public long getItemId(int id) 
    {
        return id;
    }
}

以下是我的listview的代码

protected void onCreate(Bundle savedInstanceState) 
{
      mall_data = (ListView) findViewById(R.id.list_shops);
      setListView();
}

public void setListView()
{
     MallListAdapter adapter = new MallListAdapter(this, sqlLiteData);
     mall_data.setAdapter(adapter);
     mall_data.setOnItemClickListener(new OnItemClickListener() 
     {
        int last_position=0;
        @Override
         public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
         {

             select_line = sqlLiteData.get(position).get(2); // id_shop
             select_date = sqlLiteData.get(position).get(1); // Date
             type_evt   = sqlLiteData.get(position).get(3); // type evt
             id_n_evt   = sqlLiteData.get(position).get(4); // id_
             if(type_evt.equals("F")){
                 add_date.setVisibility(View.GONE);
             }else{
                 add_date.setVisibility(View.VISIBLE);
             }
             mall_data.getItemAtPosition(0);
             edit_conc.setVisibility(View.VISIBLE);
             if(list_id.get(position).equals(id_user) || admin_user.equals("1")){
                 delete_conc.setVisibility(View.VISIBLE);
             }
             //here I force background color                        
             parent.getChildAt(last_position).setBackgroundColor(0x00000000);
             parent.getChildAt(position).setBackgroundColor(getResources().getColor((android.R.color.holo_blue_light)));
             last_position  = position;
         }
});            

0 个答案:

没有答案