我有关于Listview和CheckBox
的问题
我正在使用以下ListView
数据
JSON
{
"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
也在列表末尾,即列表视图的最后一项,我显示了dropDown按钮来添加金额。现在我应该要什么
当我选中ListView
的下拉金额菜单listItem时,最后一行必须是可见的Vise-Versa
这些代码必须写入getView方法
答案 0 :(得分:0)
您可以使用view.setVisibility(View.VISIBLE)或view.setVisibility(View.INVISIBLE)设置Layout Visible和Invisibile
答案 1 :(得分:0)
在此示例中,使用了存储所选行的id的字符串变量
MainActivity
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;
}
}
}