我有一个问题,我有一个活动,其中我显示的列表视图具有不同用户的用户图像和单选按钮,而我选择单选按钮,它被选中并切换到另一个。没关系,但是按下后退按钮并返回相同的活动时出现问题。当我按下后退按钮并再次在屏幕上显示相同的活动时,它会在任何用户的单选按钮上显示默认标记,大部分时间它将位于第一位置。虽然我要标记不同的配置文件,但它会带有默认标记的单选按钮和最近的标记按钮。我尝试使用 adapter1.notifyDataSetChanged()删除然后清除所有可见性但在执行操作时显示空白单选按钮但其执行操作但未显示我选择的单选按钮。 这里是我的代码`
public class Suite_Twit_profilelist extends Activity {
public static Button proceedT;
RadioButton radioButton2;
public List<MyComposeObject> connecteds = new ArrayList<MyComposeObject>();
public MyComposeObject composeObject;
public ListView listViewT;
public ProfilelistAdapter1 adapter1;
String profile_id = null;
// soap parameters for getting twitter User information
private static String SOAP_ACTION_OAUTHTOKEN = "******";
private static String NAMESPACE_OAUTHTOKEN = "******";
private static String METHOD_NAME_OAUTHTOKEN = "******";
private static String URL_OAUTHTOKEN = "******";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.suite_twit_profilelist);
proceedT = (Button) findViewById(R.id.buttonTwitfl);
listViewT = (ListView) findViewById(R.id.listViewtwitfl);
proceedT.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (radiobutton_selected1.equals("yes"))
new CallToFavourite().execute("");
else
Suite_Login.showToast(getApplicationContext(),
" Please select some profile ");
}
});
for (int i = 0; i < Suite_Login.composeObjectslist.size(); i++) {
if (Suite_Login.composeObjectslist.get(i).getCom_profileType()
.equals("twitter")) {
composeObject = new MyComposeObject();
composeObject
.setCom_ProfileName(Woosuite_Login.composeObjectslist
.get(i).getCom_ProfileName());
composeObject
.setCom_ProfileImgUrl(Woosuite_Login.composeObjectslist
.get(i).getCom_ProfileImgUrl());
composeObject
.setCom_ProfileImgUrl(Suite_Login.composeObjectslist
.get(i).getCom_ProfileImgUrl());
composeObject
.setCom_profileId(Woosuite_Login.composeObjectslist
.get(i).getCom_profileId());
connecteds.add(composeObject);
}
}
adapter1 = new ProfilelistAdapter1(Suite_Twit_profilelist.this,
R.layout.suite_twitte_inflater, connecteds);
listViewT.setAdapter(adapter1);
}// end of oncreate
public class CallToFavourite extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
System.out.println("OAUTHTOKEN " + Singleton.OAUTHTOKEN);
System.out.println("OAUTHSECRET " + Singleton.OAUTHSECRET);
System.out.println("FB_CMT_MESSAGE_ID "
+ Singleton.FB_CMT_MESSAGE_ID);
TwitterFactory factory = new TwitterFactory();
Twitter twitter = factory.getInstance();
// Setting customer key and customer secret key
twitter.setOAuthConsumer(TwitterValues.CONSUMER_KEY,
TwitterValues.CONSUMER_SECRET);
// Setting access token,and access Token secret
AccessToken accessToken = new AccessToken(Singleton.OAUTHTOKEN,
Singleton.OAUTHSECRET);
twitter.setOAuthAccessToken(accessToken);
try {
twitter.createFavorite(Long
.parseLong(Singleton.FB_CMT_MESSAGE_ID));
} catch (TwitterException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
Suite_Login.showToast(getApplicationContext(),
"successfully favourite");
}
}
private static LayoutInflater inflater = null;
public static String radiobutton_selected1 = "no";
public class ProfilelistAdapter1 extends ArrayAdapter<MyComposeObject> {
public ImageLoader imageLoader;
public Context mContext;
int row;
public List<MyComposeObject> arrayList;
// for radio button
private RadioButton mCurrentlyCheckedRB2;
private boolean userSelected2 = false;
private int mResourceId2 = 0;
private RadioButton mSelectedRB2;
private int mSelectedPosition2 = -1;
public ProfilelistAdapter1(Context context, int resource,
List<MyComposeObject> objects) {
super(context, resource, objects);
// TODO Auto-generated constructor stub
mContext = context;
row = resource;
arrayList = objects;
imageLoader = new ImageLoader(context);
}
@Override
public Context getContext() {
// TODO Auto-generated method stub
return mContext;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
System.out.println("arrayList.size() " + arrayList.size());
return arrayList.size();
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
System.out.println("view");
ViewHolder holder;
if (convertView == null) {
inflater = (LayoutInflater) mContext
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(row, null);
holder = new ViewHolder();
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.username_TextView2 = (TextView) convertView
.findViewById(R.id.textView777);
holder.radioButton2 = (RadioButton) convertView
.findViewById(R.id.radio777);
holder.userimage_ImageView2 = (ImageView) convertView
.findViewById(R.id.imageView777);
holder.radioButton2.setTag(position);
if (position == Singleton.selected_schedular) {
if (radiobutton_selected1.equals("yes"))
holder.radioButton2.setChecked(true);
mCurrentlyCheckedRB2 = holder.radioButton2;
} else {
System.out.println("false ");
holder.radioButton2.setChecked(false);
adapter1.notifyDataSetChanged();
}
holder.radioButton2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
radiobutton_selected1 = "yes";
profile_id = arrayList.get(position).getCom_profileId();
System.out.println("profile id " + profile_id);
System.out.println("profile name "
+ arrayList.get(position).getCom_ProfileName());
new GetOauthToken().execute("");
if ((position != mSelectedPosition2 && mSelectedRB2 != null)) {
mSelectedRB2.setChecked(false);
}
mSelectedPosition2 = position;
mSelectedRB2 = (RadioButton) v;
Singleton.selected = (Integer) v.getTag();
}
});
if (arrayList.get(position).getCom_ProfileName() != null) {
holder.username_TextView2.setText(arrayList.get(position)
.getCom_ProfileName());
adapter1.notifyDataSetChanged();
}
if (arrayList.get(position).getCom_ProfileImgUrl() != null) {
imageLoader.DisplayImage(arrayList.get(position)
.getCom_ProfileImgUrl(), holder.userimage_ImageView2);
}
return convertView;
}
private class ViewHolder {
ImageView userimage_ImageView2;
TextView username_TextView2;
CheckBox checkBox2;
RadioButton radioButton2;
}
}
/*** class for getting twitter oauth secret and oauth token ***/
public class GetOauthToken extends AsyncTask<String, Void, String> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
Suite_Login.showProgressDialog(Suite_Twit_profilelist.this);
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String result = null;
System.out.println("background Get twitter oauthToken");
SoapObject request = new SoapObject(NAMESPACE_OAUTHTOKEN,
METHOD_NAME_OAUTHTOKEN);
// Use this to add parameters
System.out.println("user_id " + Singleton.user_id);
request.addProperty("UserId", Singleton.user_id);
System.out.println("TwitterId " + profile_id);
request.addProperty("TwitterId", profile_id);
// Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
try {
HttpTransportSE androidHttpTransport = new HttpTransportSE(
URL_OAUTHTOKEN);
androidHttpTransport.debug = true;
// this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION_OAUTHTOKEN, envelope);
SoapObject soap_result = (SoapObject) envelope.bodyIn;
System.out.println("soap_result " + soap_result);
result = soap_result.getProperty(0).toString();
// System.out.println("result " + result);
JSONObject jsonObject = new JSONObject(result);
Singleton.OAUTHTOKEN = jsonObject.getString("OAuthToken");
System.out.println("Singleton.OAUTHTOKEN "
+ Singleton.OAUTHTOKEN);
Singleton.OAUTHSECRET = jsonObject.getString("OAuthSecret");
System.out.println("Singleton.OAUTHSECRET "
+ Singleton.OAUTHSECRET);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
}
}
`