Android: personalizar exibição de lista, exibição de tabela no adaptador
Criei uma exibição de tabela no adaptador de exibição de lista programaticamente. Para isso, criei um layout de adaptador como:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:stretchColumns="*"
android:id="@+id/tablelayout" >
</ableLayout>
Então o que eu fiz no adaptador é:
public class DemoAdapter extends ArrayAdapter<String> {
//Global Variable declaration
Context myContext;
String[] key, value, loop;
public DemoAdapter(Context context, String[] key, String[] value, String[] loop){
super(context, R.layout.demo_screen_adapter, loop);
this.myContext = context;
this.key = key;
this.value = value;
this.loop = loop;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
View row = convertView;
if (row == null){
// get reference to the activity
LayoutInflater inflater = ((Activity) myContext).getLayoutInflater();
// Inflate the custom text which will replace the default text view
//list_item is a simple linear layout which contain textView1 in it.
row = inflater.inflate(R.layout.demo_screen_adapter, parent, false);
}
TableLayout tableLayout = (TableLayout) row.findViewById(R.id.tablelayout);
for(int i=0; i<5; i++){
TableRow tableRow = new TableRow(myContext);
tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
TextView tvKey = new TextView(myContext);
tvKey.setText(key[(position*5)+i]);
tvKey.setTextColor(Color.WHITE);
tvKey.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
tableRow.addView(tvKey);
TextView tvValue = new TextView(myContext);
tvValue.setText(value[(position*5)+i]);
tvValue.setTextColor(Color.WHITE);
tvValue.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
tableRow.addView(tvValue);
tableLayout.addView(tableRow, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT));
}
return row;
}
}
Isso está funcionando bem. No meu item de cada lista, há uma exibição de tabela que contém cerca de duas colunas e cinco linhas.
Agora oquestão é:
Quero buscar os valores perticulares ao clicar no item da lista. Eu não sou capaz de fazê-lo. O que eu tentei como:
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Toast.makeText(this, ""+(String) arg0.getItemAtPosition(position), Toast.LENGTH_LONG).show();
}
Mas mostra a posição em que clico.
O que devo fazer para isso, por favor me guie.