我有ListView,它有一些事件.事件按日排序,我希望每天都有标题日期,然后在下面收听事件.
以下是我填充该列表的方式:
ArrayList<TwoText> crs = new ArrayList<TwoText>();
crs.add(new TwoText("This will be header", event.getDate()));
for (Event event : events) {
crs.add(new TwoText(event.getStartString() + "-" + event.getEndString(), event.getSubject()));
}
arrayAdapter = new TwoTextArrayAdapter(this, R.layout.my_list_item, crs);
lv1.setAdapter(arrayAdapter);
Run Code Online (Sandbox Code Playgroud)
这就是我的类TwoText看起来的样子:
public class TwoText {
public String classID;
public String state;
public TwoText(String classID, String state) {
this.classID = classID;
this.state = state;
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我的TwoTextArrayAdapter类的外观:
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class TwoTextArrayAdapter extends …
Run Code Online (Sandbox Code Playgroud) 我试图在导航抽屉中添加垂直线性布局(标题,图像,菜单标题,列表视图和底部的图标).然而,应用程序崩溃显示
'java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams'
Run Code Online (Sandbox Code Playgroud)
错误.我不确定这是否可能是直接的方式,因为我检查了几个链接,我得到的唯一关闭是这个.任何帮助表示赞赏.提前致谢.这是我的代码.
<!-- The main context view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<LinearLayout
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#fff"
android:gravity="bottom|center"
android:orientation="vertical"
android:paddingTop="30dp" >
<ListView
android:id="@+id/left_drawer"
android:choiceMode="singleChoice"
android:divider="#E8E8E8"
android:dividerHeight="1dp"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:src="@drawable/footer_image" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
现在的问题是,xml不允许我为listview定义宽度和高度(Element未知),我也无法运行它,因为编译器说"你必须提供layout_width"属性?请帮忙.
我的代码与scrollview.
<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" >
<!-- The main context view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ScrollView
android:id="@+id/leftRL"
android:layout_width="240dp"
android:layout_height="match_parent" …
Run Code Online (Sandbox Code Playgroud) http://developer.android.com/design/patterns/navigation-drawer.html
我已经阅读了教程以创建导航抽屉,但我还需要做什么来使用标题,图标和计数器作为抽屉项目的一部分?我只在示例中看到如何控制文本.