问题描述
我有一个的ArrayList
包含一个的HashMap
。 HashMap中包含一个主题名称,名称和值。例如的HashMap
对象是这样的。(我没有添加键的例子。)
I have a Arraylist
that contain a hashmap
. hashmap contain a Topic name, Name and value. For example hashmap
object like this.(I did not add the key for the example.)
{"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"}
我想要这样的列表视图
I want to make a list view like this
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位置,查看convertView,父母的ViewGroup)
方法................
Here is my getView(int position, View convertView, ViewGroup parent)
method................
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>
我尝试这样做,与使用添加位置
值 getView
方法内的条件。但我感到困惑。
可以请别人建议我做什么..............
I try to do that with add a condition inside of the getView
method using position
value. But it confused me. Can please someone suggest me what to do..............
推荐答案
请一些像这样的事情,也可以改变,我只是增加一个样本
Do some thing like this, You can make changes, i am just adding a sample
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);
String topic = "";
if(!(myArrayList.get(position).get("Topic").equals(topic )))
{
mTopic.setText(myArrayList.get(position).get("Topic"));
topic = myArrayList.get(position).get("Topic");
}else{
mTopic.setText("");}
mItemname.setText(myArrayList.get(position).get(
"Name"));
mValue.setText(myArrayList.get(position).get("Value"));
return v;
}
这篇关于如何在Android设备上查看getView添加条件(INT位置,查看convertView,父母的ViewGroup)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!