如何设置 item 被选中的效果.

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:id="@+id/project_task_pre_lv">



    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical"
    android:id="@+id/project_task_pre_type_lv">



final ListView lvPreTask = (ListView) view.findViewById(R.id.project_task_pre_lv);
final ListView lvType = (ListView) view.findViewById(R.id.project_task_pre_type_lv);

lvPreTask.setAdapter(new MPreTaskAdapter(preTaskList));

Map, String> typeMap = ProjectTaskParams.initTypeMap();

final List typeCodeList = new ArrayList<>();
List typeList = new ArrayList<>();

for (int key : typeMap.keySet()) {
    typeCodeList.add(key);
    typeList.add(typeMap.get(key));
}

lvType.setAdapter(new MPreTaskTypeAdapter(typeCodeList, typeList));

lvPreTask.setItemsCanFocus(true);// ListViewitem获得焦点
lvPreTask.setChoiceMode(ListView.CHOICE_MODE_SINGLE);// 单选模式
// 默认第一个item被选中
lvPreTask.setItemChecked(0, true);

lvType.setItemsCanFocus(true);// ListViewitem获得焦点
lvType.setChoiceMode(ListView.CHOICE_MODE_SINGLE);// 单选模式
// 默认第一个item被选中
lvType.setItemChecked(0, true);

lvPreTask.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView parent, View view, int position, long id) {

        preTaskSelectPosition = position;
    }
});

lvType.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView parent, View view, int position, long id) {

        preTaskTypeSelectPosition = position;
    }
});

你可能感兴趣的:(如何设置 item 被选中的效果.)