我想在点击否定复选框时更改字符串值serviceName = negative,并在检查肯定复选框时更改字符串值,所以它从服务器获取动态值。
"http://172.25.xx.yy:8080/SampleRestService/rest/hello/messages/"+StaticValue.sample+"/"+ serviceName +")).get();
这里我想分别点击checkBox positive r negative时将serviceName更改为正数或负数。
错误:我正在使用ViewPager。 单击checkbox时,值不会传递给serviceName。我想刷新片段或传递值的任何其他方式
Juz我想在单击复选框时将服务的值更改为负值,但是片段没有重新加载,因为它在viewPager中,所以它仍然是serviceName = positive本身....
package com.db.socialmedia;
//implements OnItemSelectedListener
public class MessageNegative extends Fragment {
CheckBox positive_checkbox ;
CheckBox negative_checkbox ;
public String[] Message;
public String[] Date;
private Spinner Category_spinner;
public GraphicalView messagesview;
public static String serviceName="positive";
private ArrayList<String> messagesNegativeArray=null;
private ArrayList<String> dateAndTime=null;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View V = inflater.inflate(R.layout.messaged, container, false);
boolean isChecked = true;
positive_checkbox = (CheckBox)V.findViewById(R.id.layout_Message_positive_checkbox);
negative_checkbox = (CheckBox)V.findViewById(R.id.layout_Message_negative_checkbox);
//To make positive as default selected
positive_checkbox.setChecked(isChecked);
// Inorder to make single selection of check box
positive_checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
positive_checkbox.setChecked(true);
negative_checkbox.setChecked(false);
Toast.makeText(getActivity(), "positive clicked",
Toast.LENGTH_LONG).show();
}}
});
System.out.println("0");
negative_checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
positive_checkbox.setChecked(false);
negative_checkbox.setChecked(true);
Toast.makeText(getActivity(), "negative clicked",
Toast.LENGTH_LONG).show();
}}
});
negative_checkbox.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
// MessagePositive.serviceName="neagtive"; }
});
positive_checkbox.setOnClickListener(new View.OnClickListener()
{
public void onClick(View arg0) {
// MessagePositive.serviceName="positive"; }
});
//service
try{
String restServiceResponse= new RestServiceManager().execute(
"http://172.25/SampleRestService/rest/hello/messages/"+StaticValue.sample+"/"+ serviceName +")).get();
System.out.println(restServiceResponse);
//positive.setText(negativeValue);
//Toast.makeText(this, restServiceResponse, 2000).show();
JSONObject jsonObject1 = new JSONObject(restServiceResponse);
JSONArray jsonArray2=jsonObject1.getJSONArray("messagesStatusArray");
messagesNegativeArray=new ArrayList<String>();
dateAndTime=new ArrayList<String>();
for(int messageNegative=0;messageNegative<jsonArray2.length();messageNegative++)
{
messagesNegativeArray.add(jsonArray2.getJSONObject(messageNegative).getString("messagesStatus"));
....
....
/------------------------------------------------------
This is my ViewPager
//--------------------------------------------------
Here MessagePositive fragment class will be called...
package com.db.socialmedia;
import java.util.List;
import java.util.Vector;
import com.db.socialmedia.R;
import com.db.socialmedia.FirstFragment;
import com.db.socialmedia.FirstFragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* * The <code>ViewPagerFragmentActivity</code> class is the fragment activity
* hosting the ViewPager * @author mwho
*/
public class ViewPagerFragmentAOrganisation extends Fragment {
/** maintains the pager adapter */
private PagerAdapter mPagerAdapter;
public static View android;
public static ViewPager pager,pagerN;
/*
* (non-Javadoc) * @see
* android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
android = inflater.inflate(R.layout.viewpager_layout, container, false);
// initialsie the pager
this.initialisePaging();
return android;
}
/** * Initialise the fragments to be paged */
public void initialisePaging() {
List<Fragment> fragments = new Vector<Fragment>();
//fragments.add(Fragment.instantiate(getActivity(),SAPiechartTab.class.getName()));
fragments.add(Fragment.instantiate(getActivity (),BarChartOrganisation.class.getName()));
fragments.add(Fragment.instantiate(getActivit(),SentimentAnalysisOrganisation.class.getName()));
fragments.add(Fragment.instantiate(getActivity(),MessagePositive.class.getName()));
this.mPagerAdapter = new PagerAdapter(super.getChildFragmentManager(),
fragments);
//
pager = (ViewPager) android.findViewById(R.id.viewpager);
pager.setAdapter(this.mPagerAdapter);
pager = (ViewPager) android.findViewById(R.id.viewpager);
pager.setAdapter(this.mPagerAdapter);
}
public void setPager(int currentPosition) {
pager.setCurrentItem(currentPosition);
}
}