【发布时间】:2015-05-20 05:26:39
【问题描述】:
我有一个Arraylist,其中包含一个hashmap。 hashmap 包含一个主题名称、名称和值。例如hashmap这样的对象。(我没有为示例添加密钥。)
{"Topic A", "Name 1" , "100"}
{"Topic A", "Name 2" , "100"}
{"Topic A", "Name 3" , "100"}
{"Topic A", "Name 4" , "100"}
{"Topic B", "Name 1" , "100"}
{"Topic B", "Name 2" , "100"}
{"Topic B", "Name 3" , "100"}
{"Topic B", "Name 4" , "100"}
{"Topic C", "Name 1" , "100"}
{"Topic C", "Name 2" , "100"}
{"Topic C", "Name 3" , "100"}
{"Topic C", "Name 4" , "100"}
{"Topic D", "Name 1" , "100"}
{"Topic D", "Name 2" , "100"}
我想做一个这样的列表视图
Topic A
=========================
name 1 100
name 2 100
name 3 100
name 4 100
Topic B
==========================
name 1 100
name 2 100
name 3 100
name 4 100
Topic C
==========================
name 1 100
name 2 100
name 3 100
name 4 100
Topic D
==========================
name 1 100
name 2 100
name 3 100
name 4 100
这是我的getView(int position, View convertView, ViewGroup parent) 方法......
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null)
v = inflater.inflate(R.layout.list_view_card_type, null);
mTopic = (TextView) v.findViewById(R.id.topic);
mItemname = (TextView) v.findViewById(R.id.name_of_item);
mValue = (TextView)v.findViewById(R.id.value_of_item);
mTopic.setText(myArrayList.get(position).get("Topic"));
mItemname.setText(myArrayList.get(position).get(
"Name"));
mValue.setText(myArrayList.get(position).get("Value"));
return v;
}
这是我的列表视图。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#ffffff"
android:orientation="vertical" >
<TextView
android:id="@+id/topic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="10dp"
android:textSize="28dp" />
<TextView
android:id="@+id/name_of_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="10dp"
android:textSize="28dp" />
<TextView
android:id="@+id/value_of_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="10dp"
android:textSize="28dp" />
</LinearLayout>
我尝试使用position 值在getView 方法内添加一个条件。但这让我很困惑。
可以请人建议我该怎么做........
【问题讨论】:
-
添加一些数组列表的代码..
-
没有键你怎么能检查这个
myArrayList.get(position).get("Topic")?你在哪里设置Topic作为键进入hashmap? -
创建您的项目文件,其中包含主题和名称和值的 1 行,然后检查主题值是否相同,然后设置主题的可见性消失,否则可见
-
每次视图更改时都会回收列表视图中的项目。您需要在 ViewHolder 中保存视图对象。例如:javacodegeeks.com/2013/09/…
-
'myArrayList' 有值。我检查了调试选项。没关系。我想知道如何在 'getView' 方法中添加这样的条件。
标签: android android-listview android-arrayadapter