다음은 Android 4.1 이상을 타겟팅하는 앱입니다. listview에서 활성 상태를 원합니다. 이 앱이 제대로 작동하는 다른 앱에서 코드를 사용하고 있습니다. 차이가 무엇인지 여기에 있습니다 (API 버전이 더 높음).Android ListView CHOICE_MODE_SINGLE이 (가) 설정되지 않음
DrawerAdapter lAdapter = new DrawerAdapter(this, modeList);
mDrawerList.setAdapter(lAdapter);
mDrawerList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
mDrawerList.setItemChecked(0, true);
mDrawerList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int pos,
long id) {
mDrawerList.setItemChecked(pos, true);
}
서랍 레이아웃 :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/main_frag"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/drawer_list"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:cacheColorHint="#ececec"
android:background="@drawable/tile_repeat"
android:fadingEdge="none"
android:listSelector="@drawable/nav_selector"
android:scrollbars="none" />
</android.support.v4.widget.DrawerLayout>
선택기 :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- pressed -->
<item android:drawable="@drawable/nav_press" android:state_activated="false" android:state_pressed="true"/>
<!-- CHECKED -->
<item android:drawable="@drawable/nav_active" android:state_activated="true" android:state_pressed="false" />
</selector>
nav_active :
나는이 자바를
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#cecece" />
</shape>
단계가 빠졌습니까? 프레스 상태가 잘 작동, 그냥 활성화되지 않습니다. DrawerAdapter
row_drawer_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tvMenuItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textColor="#005348"/>
</LinearLayout>
의
루트보기 DrawerAdapter :
public class DrawerAdapter extends ArrayAdapter<String> {
private final Context context;
public DrawerAdapter(Context context, String[] sizeList) {
super(context, 0, sizeList);
this.context = context;
}
static class ViewHolder {
public TextView tv1;
public TextView tv2;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
rowView = inflater.inflate(R.layout.row_drawer_layout, null, true);
holder = new ViewHolder();
holder.tv1 = (TextView) rowView.findViewById(R.id.tvMenuItem);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
String s = getItem(position);
holder.tv1.setText(s);
return rowView;
}
}
'DrawerAdapter.getView' 메소드의 기본보기는 무엇입니까? – Blaz
@blazsolar 위 코드를 ..,. – KickingLettuce