我使用带有自定义适配器的 ListView 来构建带有复选框的列表。现在我不知道如何从选定的框中获取“ID”。
项目的 xml 文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView android:id="@+id/class_open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:onClick="clickHandler" />
<TextView
android:id="@+id/medi_name"
android:text="Test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/checkbox" />
</RelativeLayout>
我需要来自:“class_open”的值
这是我的活动:
package de.bodprod.dkr;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class MediNotmediUserListNew extends Activity{
LayoutInflater inflater;
ArrayList<HashMap<String, Object>> medi_notmedi_items;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.medi_notmedi_user_list_new);
ListView mediListCheck = (ListView) findViewById(android.R.id.list);
inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
medi_notmedi_items = new ArrayList<HashMap<String,Object>>();
SystemDatabaseHandler db = new SystemDatabaseHandler(getApplicationContext());
medi_notmedi_items = db.getAllNotmedis();
final CustomAdapter adapter = new CustomAdapter(this, R.layout.medi_notmedi_user_list_new, medi_notmedi_items);
mediListCheck.setAdapter(adapter);
}
public void clickHandler(View view) {
}
private class CustomAdapter extends ArrayAdapter<HashMap<String, Object>>{
public CustomAdapter(Context context, int textViewResourceId, ArrayList<HashMap<String, Object>> Strings) {
super(context, textViewResourceId, Strings);
}
private class ViewHolder{
TextView class_open, title;
}
ViewHolder viewHolder;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView==null){
convertView=inflater.inflate(R.layout.medi_notmedi_user_list_new_item, null);
viewHolder=new ViewHolder();
viewHolder.class_open=(TextView) convertView.findViewById(R.id.class_open);
viewHolder.title=(TextView) convertView.findViewById(R.id.medi_name);
convertView.setTag(viewHolder);
}else{
viewHolder=(ViewHolder) convertView.getTag();
}
viewHolder.class_open.setText(medi_notmedi_items.get(position).get("sql_id").toString());
viewHolder.title.setText(medi_notmedi_items.get(position).get("wirk").toString());
return convertView;
}
}
}
如何从 clickHandler 的 class_open 字段中获取值?
- 是否可以将值直接分配给复选框并请求它?
- 是否可以从 class_open 字段请求值?
请原谅我的英语不好
马库斯