简体   繁体   English

两行-列表视图中的单个项目-如何?

[英]Two line - single item inside a list view - how to?

How do i do it? 我该怎么做? i've searched and looked and still haven't found anything usefull for me. 我已经搜索并查找,但仍然找不到对我有用的东西。

I currently have 2 arraylist. 我目前有2个arraylist。 first one includes Strings of calculations i got from a previous activity. 第一个包括我从上一个活动获得的计算字符串。 second one includes Doubles of results of the above mentioned calculations i got from a previous acitivty. 第二个是我从先前的活动中获得的上述计算结果的两倍。

I've saved both Arraylists in SQLLITE database. 我已经将两个Arraylists保存在SQLLITE数据库中。

The best i got so far is: 到目前为止,我得到的最好成绩是:

inside onCreate: 里面的onCreate:

SimpleAdapter adapter = new SimpleAdapter(this, list,
            R.layout.custom_row_view,
            new String[] { "operationName", "operationValue" }, new
                            int[] { R.id.text1,R.id.text2 });
populateList();
setListAdapter(adapter);

inside a function - populateList(); 在函数内部-populateList(); :

static final ArrayList<HashMap<String, Double>> list = new ArrayList<HashMap<String, Double>>();

private void populateList() {

HashMap<String, Double> temp = new HashMap<String, Double>();
for (int i = 1; i <= 20; i++) {
    temp.put(operationNames.get(i), operationValues.get(i));
}

list.add(temp);
}

EDIT: The custom_row_view .xml: 编辑:custom_row_view .xml:

<?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="fill_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/tv1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#CBC300"
    android:textSize="16sp"
    android:textStyle="bold" />

<TextView
    android:id="@+id/tv2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#3200A3"
    android:textSize="16sp"
    android:textStyle="bold" />

</LinearLayout>

What am i missing here? 我在这里想念什么? it keeps crashing when entering this specific listactivity. 输入此特定的listactivity时,它总是崩溃。

Any help will be really appreciated. 任何帮助将不胜感激。

in your code you try to get third element from list of 2 elements! 在您的代码中,您尝试从2个元素的列表中获取第三个元素! You can set some default values to this list or show only 2 items. 您可以为此列表设置一些默认值,或仅显示2个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Hashmap的单行中插入String和Drawable两个项目? - How to insert two item which are String and Drawable in a single line of Hashmap? 如何使用自定义适配器为列表视图内的项目设置ItemClickListener? - How to set an ItemClickListener for an item inside the list view with custom adapter? 如何在Android中使用two_line_list_item? - How to use the two_line_list_item in android? 当我单击列表视图项时,如何启用复选框单选 - how to enable check box single checked when i click on item of list view item 如何在回收者视图的单个项目中更新视图 - how to update view in a single item of recycler view 如何动画视图内的一条线 - How to animate a line inside a View 如何在 android 的单个片段中隐藏回收器视图的视图(但在两个片段中使用相同的列表) - How to hide a view of recycler view in a single fragment in android (But using same list in two fragments) 在一行上创建项目列表,然后查询列表以查看项目是否存在,而不在Java中接收未经检查的转换警告 - Create a list of item on a single line, then query list to see if item exists, without receiving unchecked conversion warning in Java Android列表视图仅显示两个中的一个项目 - Android List View Showing only one item from two 单项单击列表 - Single Item Click in a list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM