所以我有一个应用程序,我从sqlite数据库中获取一些民意调查并在listview中使用它们,现在我尝试添加一个单选按钮但是当我点击一个按钮后,我创建它并没有保存选择我是从单选按钮做的。
我打开应用程序并......
but when i go back and in again the first is selected
这是我的listAdapter.java
package com.hfad.myapp.adapter;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;
import com.hfad.myapp.R;
import com.hfad.myapp.model.Cases;
import java.util.List;
public class ListCases extends BaseAdapter {
private Context mContext;
private List<Cases> mCasesList;
public ListCases(Context mContext, List<Cases> mCasesList) {
this.mContext = mContext;
this.mCasesList = mCasesList;
}
int pose = 0;
@Override
public int getCount() {
return mCasesList.size();
}
@Override
public Object getItem(int position) {
return mCasesList.get(position);
}
@Override
public long getItemId(int position) {
return mCasesList.get(position).getID();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = View.inflate(mContext, R.layout.item_listview, null);
TextView tvName = (TextView)v.findViewById(R.id.tv_case_name);
TextView tvSize = (TextView)v.findViewById(R.id.tv_case_size);
TextView tvMsize = (TextView)v.findViewById(R.id.tv_case_msize);
RadioButton radioButton = (RadioButton)v.findViewById(R.id.radioButton);
radioButton.setChecked(position == pose);
radioButton.setTag(position);
radioButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pose = (Integer)view.getTag();
notifyDataSetChanged();
}
});
tvName.setText(mCasesList.get(position).getBrand());
tvSize.setText(mCasesList.get(position).getSize());
tvMsize.setText(mCasesList.get(position).getMsize());
return v;
}
}
我提醒您,我与外部数据库建立了数据库连接 我真的很沮丧,我找不到类似的东西,我无法解决这个问题,请帮忙。 附:对于任何错误......我在java和android studio中都是新手。