3


我对 Listview 有疑问,我正在使用以下数据CheckBox
创建自定义ListViewJSON

{
            "title": "Amount Field",
            "settingItems": [
              {
                "title": "Manual Entry",
                "type": "boolean",
                "value": true
              },
              {
                "title": "Predefined Amount",
                "type": "Amount",
                "value": 0.00
              },
              {
                "title": "Drop Down Amount Menu",
                "type": "boolean",
                "value": false
              },
              {
                "title": "",
                "type": "Amount",
                "value": 0.00
              }
            ]
          }

使用上述数据,我还管理了我Listview的列表末尾,即列表视图的最后一项,显示下拉按钮以添加金额。现在,
当我检查下拉金额菜单 listItem 时我应该想要什么,ListView那么最后一行也必须可见 Vise-Versa
代码必须写入 getView 方法

4

2 回答 2

0

您可以使用 view.setVisibility(View.VISIBLE) 或 view.setVisibility(View.INVISIBLE) 设置布局可见和不可见

于 2013-02-25T11:15:18.883 回答
0

在此示例中,使用了存储所选行 id 的字符串变量

主要活动

public class MainActivity extends Activity {

 static final String TAG_NAME = "name";
 static final String TAG_ID = "id";
 static String selected = "";

ListView listView;


HashMap<String, String> map;
ArrayList<HashMap<String,String>> myList;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    myList = new ArrayList<HashMap<String,String>>();       
    listView = (ListView) findViewById(R.id.listView1);
    fillListView();
}

private void fillListView() {

    myList.clear();

    map = new HashMap<String, String>();
    map.put(TAG_ID,"1");
    map.put(TAG_NAME, "Name1");
    myList.add(map);

    map = new HashMap<String, String>();
    map.put(TAG_ID,"2");
    map.put(TAG_NAME, "Name2");
    myList.add(map);

    map = new HashMap<String, String>();
    map.put(TAG_ID,"3");
    map.put(TAG_NAME, "Name3");
    myList.add(map);

    map = new HashMap<String, String>();
    map.put(TAG_ID,"4");
    map.put(TAG_NAME, "Name4");
    myList.add(map);

    listView.setAdapter(new MyListAdapter(this, R.layout.row, myList));

}
private class MyListAdapter extends BaseAdapter 
{

    private List<HashMap<String,String>> List;
    private LayoutInflater mInflater;
    private int layoutresource;

    public MyListAdapter(Context context,int resource,List<HashMap<String, String>> myList) {
        List = myList;
        mInflater = LayoutInflater.from(context);
        layoutresource = resource;
    }

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

    @Override
    public Object getItem(int position) {
        return List.get(position);
    }

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

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = mInflater.inflate(layoutresource,null);
        }    

         final View rootView = convertView.findViewById(R.id.root);

        ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView1);
        final TextView name = (TextView) convertView.findViewById(R.id.textView1);

        imageView.setImageDrawable(getResources().getDrawable(R.drawable.profile));
        name.setTextColor(Color.parseColor("#ffffff"));
        name.setText(List.get(position).get(TAG_NAME));

        if ( List.get(position).get(TAG_ID).equals(selected))
            name.setTextColor(Color.parseColor("#ff0000"));
        else
            name.setTextColor(Color.parseColor("#ffffff"));


        rootView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                selected = List.get(position).get(TAG_ID);
                fillListView();
            }
        });

        name.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                rootView.performClick();
            }
        });

        imageView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                rootView.performClick();
            }
        });

        return convertView;
    }
}

}

于 2013-02-25T11:21:44.617 回答