Displaying Two Views in a single List Row Item in Android

房东的猫 提交于 2019-12-11 10:29:38

问题


There is a need to displaying two views in a single ListView Row . How it is possible in android. Please help me.


回答1:


You can use custom layout for your lists , here is example which is using imageview and textview in a single row. Row.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="wrap_content"
  android:orientation="horizontal"
      >
  <ImageView
  android:id="@+id/icon"
  android:padding="2dip"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:src="@drawable/ok"
  />
  <TextView
  android:id="@+id/label"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textSize="40sp"
  />
  </LinearLayout>

Here is java code ,this is an activity's onCreate extending ListActivity.

public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.main);
  setListAdapter(new ArrayAdapter<String>(this,R.layout.row, R.id.label,items));
  selection=(TextView)findViewById(R.id.selection);
  }



回答2:


Use GridView and add this to the parameters.

android:numColumns="2"

Check this first and this Kinda helped me too with the same problem. :)



来源:https://stackoverflow.com/questions/12889572/displaying-two-views-in-a-single-list-row-item-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!