我创建此列表视图
使用此代码
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:weightSum="5"
android:background="@drawable/border"
>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textStyle="bold"
android:textColor="#000000"
android:id="@+id/lblDate"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/lblDescription"
android:singleLine="true"
android:textColor="#000000"
android:ellipsize="end"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textStyle="bold"
android:textColor="#000000"
android:id="@+id/lblAmount"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textStyle="bold"
android:textColor="#000000"
android:id="@+id/lblPrice"/>
</LinearLayout>
Java代码
public class FillList extends AsyncTask<String, String, String> {
List<Map<String, String>> prolist = new ArrayList<Map<String, String>>();
@Override
protected void onPreExecute() {
}
@Override
protected void onPostExecute(String r) {
String[] from = {"D", "C", "B","A"};
int[] views = { R.id.lblPrice,R.id.lblAmount,R.id.lblDescription,R.id.lblDate};
final SimpleAdapter ADA = new SimpleAdapter(Products.this,
prolist, R.layout.lsttemplate, from,
views);
lstSoratHesab.setAdapter(ADA);
}
@Override
protected String doInBackground(String... params) {
Map<String, String> datanum = new HashMap<String, String>();
datanum.put("D", "price");
datanum.put("C", "amount");
datanum.put("B", "description");
datanum.put("A", "date");
prolist.add(datanum);
while (rs.next()) {
datanum = new HashMap<String, String>();
datanum.put("D", rs.getString("Bes"));
datanum.put("C", rs.getString("Bed"));
datanum.put("B", rs.getString("Sharh"));
datanum.put("A", rs.getString("Date"));
prolist.add(datanum);
}
}
}
[1]: https://i.stack.imgur.com/kFE56.png
由于描述太长,我想要更改列表视图
问题:如何在列表视图中更改列表视图并在新行中设置描述?
答案 0 :(得分:2)
实现此布局的最简单方法是在设计中使用两个LinearLayouts。父LinearLayout应具有垂直方向,子LinearLayout应具有水平方向。您可以在下面的代码中看到这一点:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:width="match_parent"
android:height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:width="match_parent"
android:height="wrap_content"
android:orientation="horizontal" >
<!-- Most of your TextViews go there -->
</LinearLayout>
<!-- The description TextView -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lblDescription" />
</LinearLayout>