#android #android-layout #android-listview #navigation-drawer
#Android #android-макет #android-listview #навигация-ящик
Вопрос:
Я пытаюсь добавить separator
заголовок раздела для ListView
in drawerLayout
, но я не вижу separators
, и я просто вижу заголовки.
Это мой код :
public class MainActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
public Cursor cursor;
public Cursor cursorsex;
public ArrayList<String> array;
public ArrayList<String> arraysex;
private ArrayAdapter<String> listAdapter ;
private ArrayAdapter<String> listAdaptersex ;
private ListView mDrawerList;
private ListView mDrawerListsex;
.....
Connection to sqlite
.....
sql = db.openDataBase();
cursor = sql.rawQuery("SELECT Title FROM WebSite_CategoryBack WHERE ParentID=0;", null);
array = new ArrayList<String>();
while(cursor.moveToNext()){
Titel_Drawer = cursor.getString(cursor.getColumnIndex("Title"));
array.add(Titel_Drawer);
}
cursor.close();
cursorsex = sql.rawQuery("SELECT Title FROM WebSite_CategoryBack WHERE ParentID=0;", null);
arraysex = new ArrayList<String>();
while(cursorsex.moveToNext()){
Titel_Drawer = cursorsex.getString(cursorsex.getColumnIndex("Comment"));
arraysex.add(Titel_Drawer);
}
cursorsex.close();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
mDrawerListsex = (ListView) findViewById(R.id.sex);
listAdapter = new ArrayAdapter<String>(this, R.layout.drawer_list,R.id.textView, array);
mDrawerList.setAdapter( listAdapter );
listAdaptersex = new ArrayAdapter<String>(this, R.layout.xxx,R.id.xxx, arraysex);
mDrawerListsex.setAdapter( listAdaptersex );
}
}
Это xxx.xml
:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@ id/xxx"/>
Это drawer_list.xml
:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@ id/textView"/>
Это activity_main.xml
:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@ id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- The main content view -->
<FrameLayout
android:id="@ id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:id="@ id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start">
<TextView
android:layout_width="240dp"
android:layout_height="25dp"
android:textSize="20sp"
android:gravity="center"
android:text="@string/prof"
android:background="@drawable/drawer_title_shape" />
<!-- The navigation drawer -->
<ir.makarem.extentions.ClearableEditText
android:id="@ id/SearchEdittxt"
android:drawableLeft="@drawable/ic_action_search"
android:layout_width="240dp"
android:layout_height="35dip"
android:background="@drawable/textlines"
android:gravity="right"
android:hint="@string/action_search" />
<ListView
android:id="@ id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#FFDDDDDD"/>
<ListView
android:id="@ id/sex"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#FFDDDDDD"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Например, мне нужно посмотреть, как выглядит эта фотография.
Я добавляю два TextView
для заголовка и два ListView
.
Комментарии:
1. Уродливый код. Попробуйте отделить ваши запросы от вашего кода макета.
2. для этого вам нужно добавить заголовок раздела listview.
Ответ №1:
вы должны использовать раздел заголовок listview для достижения этой функциональности
Ссылка на раздел заголовок списка
Ответ №2:
Вам нужно установить разделитель для вашего ListView
: (пример кода)
// white color for example
int[] clr = {0, 0xFFFFFFFF, 0};
listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, clr));
listView.setDividerHeight(1); // set your desired height
Или установите разделитель в .xml:
<ListView
android:id="@ id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#FFFFFF"
android:dividerHeight="2px" >
</ListView>
Комментарии:
1. Привет @Philipp Jahoda. У меня есть два ListView в моем проекте, я должен использовать один ListView для setDivider?
2. Это полностью зависит от вас. Если вы хотите, чтобы в ListView был разделитель, вы устанавливаете его, если нет, вы этого не делаете. Я действительно не понимаю вашего вопроса.