我一直致力于一个项目,我需要标记员工的出勤率并将其存储在数据库中。因为我在无线电组中实施了单选按钮,这将确定员工是否缺席或半天假。 ..要做到这一点,我必须从列表视图中获取这些值,并在点击完成按钮时,必须标记出勤并存储在数据库中....
我的问题是如何从我的自定义列表视图中获取这些单选按钮的值并处理这些数据!! ??
我的自定义列表适配器代码
public class CustomCalendarAdapter extends ArrayAdapter<String> {
private final Activity context;
private final String[] itemname;
private final Bitmap[] imgid;
public CustomCalendarAdapter(Activity context, String[] itemname, Bitmap[] imgid) {
super(context, R.layout.list_item2, itemname);
this.context=context;
this.itemname=itemname;
this.imgid=imgid;
}
@Nonnull
public View getView( int position, View view,@Nonnull ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.list_item2, null,true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.item);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
TextView extratxt = (TextView) rowView.findViewById(R.id.textView1);
final RadioButton rb1 = (RadioButton) rowView.findViewById(R.id.rb1);
final RadioButton rb2 = (RadioButton) rowView.findViewById(R.id.rb2);
final RadioButton rb3 = (RadioButton) rowView.findViewById(R.id.rb3);
rb2.setChecked(true);
txtTitle.setText(itemname[position]);
imageView.setImageBitmap(imgid[position]);
extratxt.setText("Description "+itemname[position]);
return rowView;
} }
我的列表视图代码xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/icon"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/rowselector"
android:padding="5dp" />
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="80dp"
android:layout_weight="1"
android:background="@drawable/rowselector"
android:orientation="vertical">
<TextView
android:id="@+id/item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:padding="2dp"
android:textColor="#000" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_marginLeft="10dp"/>
</LinearLayout>
<RadioGroup
android:id="@+id/rg"
android:orientation="horizontal"
android:layout_marginTop="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/rb1"
android:text="P"
android:padding="2dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:id="@+id/rb2"
android:text="A"
android:padding="2dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:id="@+id/rb3"
android:text="HD"
android:padding="2dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
我的listview活动代码,我想在其中显示列表和处理完成按钮
public class Attendance extends AppCompatActivity {
CustomCalendarAdapter adapter;
ArrayList<String> strings = new ArrayList<>();
ArrayList<Bitmap> bitmaps = new ArrayList<>();
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_attendance);
lv = (ListView) findViewById(R.id.list);
myinfodbhelper mDbHelper = new myinfodbhelper(this);
SQLiteDatabase db = mDbHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM "
+ myinfocontract.myinfoentry.TABLE_NAME,null);
while (cursor.moveToNext()) {
String currentfname = cursor.getString(cursor.getColumnIndex("name"));
byte[] bytes = cursor.getBlob(cursor.getColumnIndex("image"));
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
strings.add(currentfname);
bitmaps.add(bitmap);
}
cursor.close();
String[] itemname = strings.toArray(new String[0]);
Bitmap[] imageid = bitmaps.toArray(new Bitmap[0]);
adapter = new CustomCalendarAdapter(this, itemname, imageid);
lv.setAdapter(adapter);
lv.setEmptyView(tv);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.floatingActionButton);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Here I want to handle the radio button check
//And mark done by the floatingActionButton id in my listview xml file
}
});
如果此问题已经回答,请提供链接
我无法找到解决问题的相关解决方案因此我提出这个问题......必须做什么修改?
提前......
答案 0 :(得分:1)
第1步
使用整数变量attendance_type
创建数据的Bean类。并将该数据列表传递给您的适配器。
第2步
在您的广播组上设置点击侦听器。并将无线电检查中的attendance_type
(无论选择什么)设置为更改为列表并在数据库中进行更改。
第3步
现在每次更改出勤时间都会有更新列表。
答案 1 :(得分:0)
您可以使用以下代码
获取已检查单选按钮ID的IDint checked_btn_id = radioGroup.getCheckedRadioButtonId();
您还需要创建一个模型类来存储值并管理滚动问题Issue when scrolled down when radio checked items are not seen