我带来了两个领域的网络服务并填充了一个列表视图。
我需要一个多行文本视图。我的组件足够大,至少可以显示 4 行,但只显示 2 行。
如何在列表视图中添加更多子项?
我想在列表视图中包含更多表字段。
private void pesquisarProdutos() {
dialog = ProgressDialog.show(this, "Aguarde...",
"Pesquisando registros.", false, true);
dialog.setIcon(R.drawable.ic_launcher);
dialog.setCancelable(false);
DSRESTConnection conn = gc.getConnection();
final TServerMethods1 serv = new TServerMethods1(conn);
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
TDataSet ds;
// limpa a lista a cada pesquisa
dataList.clear();
ds = serv.ConsultaItens(VendaClienteActivity.edtItem
.getText().toString());
while (ds.next()) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("nome", ds.getValue("NOME").GetAsString());
item.put("id", ds.getValue("CODIGO").GetAsString());
dataList.add(item);
}
// desabilita o dialog
dialog.dismiss();
finalizaDialogo(false, "");
} catch (Exception e) {// desabilita o dialog
dialog.dismiss();
finalizaDialogo(true, e.toString());
}
return null;
}
}.execute();
}
private void finalizaDialogo(final boolean temErro, final String msg) {
handler.post(new Runnable() {
@Override
public void run() {
if (temErro)
Toast.makeText(ListaItensProdutosActivity.this, msg,
Toast.LENGTH_LONG).show();
else
AtualizarTela();
// finaliar o dialogo
dialog.dismiss();
}
});
}
private void AtualizarTela() {
String[] from = new String[] { "nome", "id" };
int[] to = new int[] { android.R.id.text1, android.R.id.text2 };
int layoutNativo = android.R.layout.two_line_list_item;
listItens.setAdapter(new SimpleAdapter(this, dataList, layoutNativo,
from, to));
if (listItens == null) {
Toast.makeText(ListaItensProdutosActivity.this,
"Não foi encontrado dados nesta busca.", Toast.LENGTH_LONG)
.show();
finish();
}
}
我的 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" >
<LinearLayout
android:id="@+id/layoutCabecalho"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/barra"
android:gravity="center" >
<Button
android:id="@+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancelar"
android:textSize="14sp" />
<LinearLayout
android:id="@+id/layoutCabecalhoEsquerdo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|left" >
</LinearLayout>
<LinearLayout
android:id="@+id/layoutCabecalhoCentro"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="3"
android:gravity="center" >
<TextView
android:id="@+id/textoTitulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Listagem"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="@+id/layoutCabecalhoDireito"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical|right" >
</LinearLayout>
</LinearLayout>
<ListView
android:id="@+id/listaItensProdutos"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>