0

Hi this is my singlemenuitemactivity:

public class SingleMenuItemActivity extends ExpandableListActivity {


Button btninsert;
String selectedItem;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.particular);

 Button btninsert = (Button) findViewById(R.id.btn_insert);
 btninsert.setOnClickListener(new View.OnClickListener() {



   public void onClick(View v) {
 // Switching to Register screen
 Intent i = new Intent(getApplicationContext(), InsertionExample.class);
  String s1= getIntent().getStringExtra("orderid");

  i.putExtra(KEY_NAME, orderid);
  startActivity(i);
   } 
  });    


    // Construct Expandable List
    final String NAME1 = "payment_method1";
    final String NAME = "payment_method";
    final String TOTAL = "total";
    final String TOTAL1 = "total1";
   final String ID = "orderid";
    final String ID1 = "orderid1";
    final String IMAGE = "image"; 
    final String FNAME1 = "firstname1";

    final String FNAME = "firstname";
    final String LNAME1 = "lastname1";
    final String LNAME = "lastname";

    final LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final ArrayList<HashMap<String, String>> headerData = new ArrayList<HashMap<String, String>>();

    final HashMap<String, String> group1 = new HashMap<String, String>();
    group1.put(NAME, "OrderInfo");
    headerData.add( group1 );

    final HashMap<String, String> group2 = new HashMap<String, String>();
    group2.put(NAME, "CustomerInfo");
    headerData.add( group2);

  // final HashMap<String, String> group3 = new HashMap<String, String>();
   // group3.put(NAME, "Group 3");
   // headerData.add( group3);


    final ArrayList<ArrayList<HashMap<String, Object>>> childData = new ArrayList<ArrayList<HashMap<String, Object>>>();

    final ArrayList<HashMap<String, Object>> group1data = new ArrayList<HashMap<String, Object>>();
    childData.add(group1data);

    final ArrayList<HashMap<String, Object>> group2data = new ArrayList<HashMap<String, Object>>();
    childData.add(group2data);

  //  final ArrayList<HashMap<String, Object>> group3data = new ArrayList<HashMap<String, Object>>();
  //  childData.add(group3data);

    // Set up some sample data in both groups
    for( int i=0; i<1; ++i) {
        final HashMap<String, Object> map = new HashMap<String,Object>();
        String s= getIntent().getStringExtra("payment_method");
        String s1= getIntent().getStringExtra("total");
        String selectedItem= getIntent().getStringExtra("selectedItem");
        String s5= getIntent().getStringExtra("orderid");
        map.put(NAME1, "Payment_method:");
        map.put(NAME, s );
        map.put(TOTAL1, "Total:");
        map.put(TOTAL, s1);
        map.put(ID1, "Total:");
        map.put(ID, s5);
        group1data.add(map);
     //  map.put(IMAGE, getResources().getDrawable((i%3==0? R.drawable.color_green : R.drawable.color_red)));
      //  ( i%2==0 ? group1data : group2data ).add(map);
    }
    final HashMap<String, Object> map = new HashMap<String,Object>();
    String s1= getIntent().getStringExtra("firstname");
    String s2= getIntent().getStringExtra("lastname");

    map.put(FNAME, s1);
    map.put(FNAME1, "Firstname:");
    map.put(LNAME, s2);
    map.put(LNAME1, "Lastname:");

 //  map.put(IMAGE, getResources().getDrawable(R.drawable.color_yellow));
    group2data.add(map);

    setListAdapter( new SimpleExpandableListAdapter(
            this,
            headerData,
            R.layout.group_row,
            new String[] { NAME, FNAME },    // the names of the data
            new int[] { R.id.order },   // the text field to populate with the field data
            childData,
            0,
            null,
            new int[] {}
        ) {
            @Override
            public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
                final View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);

              //  Spinner spinner = (Spinner) findViewById(R.id.spnMusketeers);

                // Populate your custom view here
                ((TextView)v.findViewById(R.id.payment_method1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(NAME1) );
                ((TextView)v.findViewById(R.id.payment_method)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(NAME) );
                ((TextView)v.findViewById(R.id.firstname)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(FNAME) );
                ((TextView)v.findViewById(R.id.firstname1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(FNAME1) );
                ((TextView)v.findViewById(R.id.total1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(TOTAL1) );
                ((TextView)v.findViewById(R.id.total)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(TOTAL) );
                ((TextView)v.findViewById(R.id.lastname)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(LNAME) );
                ((TextView)v.findViewById(R.id.lastname1)).setText( (String) ((Map<String,Object>)getChild(groupPosition, childPosition)).get(LNAME1) );


                return v;
            }

            @Override
            public View newChildView(boolean isLastChild, ViewGroup parent) {

                 return layoutInflater.inflate(R.layout.expandable_list_item_with_image,null, false);

            }
        }
    );
    ExpandableListView list = (ExpandableListView) findViewById(android.R.id.list);
    list.setOnChildClickListener(new OnChildClickListener(){
        public boolean onChildClick(ExpandableListView parent, View v,
                int groupPosition, int childPosition, long id) {
            System.out.println("Group:"+groupPosition+", Child: "+childPosition);
            return true;
        }
    });


}} 

this is my insertionexample.java

public class InsertionExample extends Activity {
private final String NAMESPACE = "http://xcart.com";
private final String URL = "http://192.168.1.168:8089/XcartLogin/services/update?wsdl";
private final String SOAP_ACTION = "http://xcart.com/insertData";
private final String METHOD_NAME = "insertData";
Button btninsert;
String selectedItem;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.change_status);

    //get reference to the spinner from the XML layout
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    btninsert = (Button)findViewById(R.id.btn_insert1);
    btninsert.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            EditText Orderid = (EditText) findViewById(R.id.orderid);
            String orderid = Orderid.getText().toString();
            TextView tv = (TextView) findViewById(R.id.textView1);
            tv.setText("Welcome ,"+getIntent().getExtras().getString("orderid"));
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            PropertyInfo unameProp =new PropertyInfo();
            unameProp.setName("Status");//Define the variable name in the web service method
           unameProp.setValue(selectedItem);//Define value for fname variable
            unameProp.setType(String.class);//Define the type of the variable
            request.addProperty(unameProp);


              SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
              envelope.setOutputSoapObject(request);
              HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

              try{
               androidHttpTransport.call(SOAP_ACTION, envelope);
                  SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

                 TextView result = (TextView) findViewById(R.id.textView2);
                  result.setText(response.toString());

           }
           catch(Exception e){

           }



        }
    });

    //attach the listener to the spinner
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

    //Dynamically generate a spinner data 
    createSpinnerDropDown();

}

//Add animals into spinner dynamically
private void createSpinnerDropDown() {

    //get reference to the spinner from the XML layout
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);

    //Array list of animals to display in the spinner
    List<String> list = new ArrayList<String>();

    list.add("Q");
    list.add("P");
    list.add("F");
    list.add("I");
    list.add("C");

    //create an ArrayAdaptar from the String Array
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
    //set the view for the Drop down list
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //set the ArrayAdapter to the spinner
    spinner.setAdapter(dataAdapter);
    //attach the listener to the spinner
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());

}

public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

         selectedItem = parent.getItemAtPosition(pos).toString();

 }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }



    }

    public void onNothingSelected(AdapterView<?> parent) {
        // Do nothing.
    }
}

here my doubt is the orderid is parsed from xml parsing...the update operation is performed soap calling..now here i have to update the status from orderid...how is to do..this is my update query.

"UPDATE `xcart_orders` set `status` = '"+Status+"' where `orderid` = '"+Orderid+"'"

please help me...how is update status depends upon orderid from xml parsing..how is change my code...how is to do...please help me

Krishna Veni
  • 2,217
  • 8
  • 27
  • 53

6 Answers6

2

Use shared preferences or Application class

Shared preferences example

Application class example

Abhi
  • 8,935
  • 7
  • 37
  • 60
2

You have 2 ways to do this:

1- Use public static values to store username and password (not recommended)

2- Use sharedPreferences as below:

in your first activity, to save username and password:

SharedPreferences data = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
data.edit().putString("UserName", userName).commit();
data.edit().putString("Password", password).commit();

in the fourth activity to retrieve username and password:

SharedPreferences data = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String userName = data.getString("UserName", "THIS IS DEFAULT VALUE");
String password = data.getString("Password", "THIS IS DEFAULT VALUE");
yrajabi
  • 637
  • 1
  • 9
  • 28
2

You can Do this using the Getters and setters methods.

create one class :

public class SelectedAnswer {

public static String uname;

public static String getAnswer() {
    return uname;
}

public static void setAnswer(String answer) {
    uname = answer;
}

}

Then set the username value into your first activty.

 SelectedAnswer.setAnswer(uName);

and get the value into fourth activity.

String answer = SelectedAnswer.getAnswer();
Rahul Patel
  • 3,823
  • 5
  • 30
  • 46
1

you can also use setter getter class to set data and access data anywhere in application by just creating object for that class. in your case this might be useful.

NaserShaikh
  • 1,576
  • 2
  • 23
  • 39
0

If you have data which must be accessed from different parts of your application you can use Singleton pattern as data holder.

Bart
  • 19,692
  • 7
  • 68
  • 77
Dmytro Danylyk
  • 19,684
  • 11
  • 62
  • 68
0

Either use some static variables to store this or use shared preference. If you have more than one activty where you need to transfer data, its better to use a static dictionary which will help you to save activity specific data.

For Example :

We can create a simple data cacher class for this :

public class MyActivityDataCacher {

private static HashMap<String, String> mDataCacher;

    static{
    mDataCacher=new HashMap<String, String>();
}

public static void putDataFor(String className, String data) {
    mDataCacher.put(className, data);
}

public static String getDataFor(String className) {
    if (mDataCacher.containsKey(className)) {
        return mDataCacher.get(className);
    } else {
        return "";
    }
}
}

For storing Data for a particular Activity (Say MainActivity) :

MyActivityDataCacher.putDataFor(MainActivity.class.getName(), "Test Data");

For Retrieving the data stored :

MyActivityDataCacher.getDataFor(MainActivity.class.getName());
Eldhose M Babu
  • 14,382
  • 8
  • 39
  • 44