本文介绍了当自定义适配器的ListView检查吐司的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想,当我在复选框选中的code返回那是在同一行文本视图的字符串只。
I want when I checked on check box the code returns string of text view that's in the same row only .
我使用LayoutInflater并具有code创建包含字符串列表中的其他类
i'm using LayoutInflater and another class which has code for creating list containing strings
我的code:
public class InteractiveArrayAdapter extends ArrayAdapter<model> {
private final List<model> list;
private final Activity context;
public InteractiveArrayAdapter(Activity context, List<model> list) {
super(context, R.layout.rep, list);
this.context = context;
this.list = list;
}
static class ViewHolder {
protected TextView text;
protected CheckBox checkbox;
}
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rep, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) view.findViewById(R.id.TextView07);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.CheckBox05);
viewHolder.checkbox
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
model element = (model) viewHolder.checkbox
.getTag();
element.setSelected(buttonView.isChecked());
}
});
view.setTag(viewHolder);
viewHolder.checkbox.setTag(list.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).checkbox.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.text.setText(list.get(position).getName());
holder.checkbox.setChecked(list.get(position).isSelected());
return view;
}
}
我的XML:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/h103"
android:layout_width="match_parent"
android:layout_height="27dp"
android:layout_x="0dp"
android:layout_y="0dp"
android:background="@drawable/back1" >
<TableRow
android:id="@+id/TableRow05"
android:layout_width="match_parent"
android:layout_height="27dp"
android:layout_marginTop="4dp" >
<CheckBox
android:id="@+id/CheckBox05"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="-4dp"
android:button="@drawable/test" />
<TextView
android:id="@+id/TextView07"
android:layout_width="220dp"
android:layout_height="22dp"
android:layout_marginLeft="23dp"
android:layout_marginTop="-6dp"
android:text="" />
<TextView
android:id="@+id/TextView08"
android:layout_width="110dp"
android:layout_height="22dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="-4dp"
android:text="095110263" />
</TableRow>
推荐答案
首先,在乌尔列表视图btnOk底部添加1按钮
First Add 1 button at bottom of ur list view btnOk
btnOk.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
StringBuffer responseText = new StringBuffer();
ArrayList<model> almodel = adapter.almodel;
responseText.append("The following were selected...\n");
for(int i=0;i<almodel.size();i++)
{
model m = almodel.get(i);
if(m.isSelected())
{
responseText.append("\n" + m.getName());
}
}
Toast.makeText(getApplicationContext(),responseText,Toast.LENGTH_LONG).show();
这篇关于当自定义适配器的ListView检查吐司的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!